Skip to content

Commit bac8a26

Browse files
committed
ACP2E-3091: [Cloud] Creating the Duplicate website group price customer group in Tier Prices Api
1 parent 2e08b17 commit bac8a26

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

app/code/Magento/Catalog/Model/Product/Price/Validation/TierPriceValidator.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Model\Product\Type;
1212
use Magento\Catalog\Model\ProductIdLocatorInterface;
1313
use Magento\Customer\Api\GroupRepositoryInterface;
14+
use Magento\Directory\Model\Currency;
1415
use Magento\Framework\Api\FilterBuilder;
1516
use Magento\Framework\Api\SearchCriteriaBuilder;
1617
use Magento\Framework\Exception\LocalizedException;
@@ -426,7 +427,7 @@ private function checkUnique(
426427
foreach ($prices[$tierPrice->getSku()] as $price) {
427428
if ($price !== $tierPrice) {
428429
$checkWebsiteValue = $isExistingPrice ? $this->compareWebsiteValue($price, $tierPrice)
429-
: ($price->getWebsiteId() == $tierPrice->getWebsiteId());
430+
: $this->compareWebsiteValueNewPrice($price, $tierPrice);
430431
if (strtolower($price->getCustomerGroup()) === strtolower($tierPrice->getCustomerGroup())
431432
&& $price->getQuantity() == $tierPrice->getQuantity()
432433
&& $checkWebsiteValue
@@ -547,6 +548,29 @@ private function compareWebsiteValue(TierPriceInterface $price, TierPriceInterfa
547548
&& $price->getWebsiteId() != $tierPrice->getWebsiteId();
548549
}
549550

551+
/**
552+
* Compare Website Values between for new price records
553+
*
554+
* @param TierPriceInterface $price
555+
* @param TierPriceInterface $tierPrice
556+
* @return bool
557+
*/
558+
private function compareWebsiteValueNewPrice(TierPriceInterface $price, TierPriceInterface $tierPrice): bool
559+
{
560+
if ($price->getWebsiteId() != $this->allWebsitesValue ||
561+
$tierPrice->getWebsiteId() != $this->allWebsitesValue
562+
) {
563+
return $price->getWebsiteId() == $tierPrice->getWebsiteId();
564+
}
565+
566+
$baseCurrency = $this->scopeConfig->getValue(Currency::XML_PATH_CURRENCY_BASE, 'default');
567+
$websiteId = max($price->getWebsiteId(), $tierPrice->getWebsiteId());
568+
$website = $this->websiteRepository->getById($websiteId);
569+
$websiteCurrency = $website->getBaseCurrencyCode();
570+
571+
return $price->getWebsiteId() == $tierPrice->getWebsiteId() && $baseCurrency == $websiteCurrency;
572+
}
573+
550574
/**
551575
* @inheritDoc
552576
*/

0 commit comments

Comments
 (0)