Skip to content

Commit 1564875

Browse files
committed
Merge branch 'ACP2E-3091' of https://github.com/adobe-commerce-tier-4/magento2ce into TIer4-PR-07-22-2024
2 parents 1a2cc41 + a3926b4 commit 1564875

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-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+
$baseCurrency = $this->scopeConfig->getValue(Currency::XML_PATH_CURRENCY_BASE, 'default');
564+
$websiteId = max($price->getWebsiteId(), $tierPrice->getWebsiteId());
565+
$website = $this->websiteRepository->getById($websiteId);
566+
$websiteCurrency = $website->getBaseCurrencyCode();
567+
568+
return $baseCurrency == $websiteCurrency;
569+
}
570+
571+
return $price->getWebsiteId() == $tierPrice->getWebsiteId();
572+
}
573+
550574
/**
551575
* @inheritDoc
552576
*/

dev/tests/api-functional/testsuite/Magento/Catalog/Api/TierPriceStorageTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,53 @@ public function testCheckWebsite()
354354
}
355355
}
356356

357+
/**
358+
* Test replace method.
359+
*
360+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
361+
*/
362+
public function testCheckNewRecords()
363+
{
364+
$serviceInfo = [
365+
'rest' => [
366+
'resourcePath' => '/V1/products/tier-prices',
367+
'httpMethod' => Request::HTTP_METHOD_POST
368+
],
369+
'soap' => [
370+
'service' => self::SERVICE_NAME,
371+
'serviceVersion' => self::SERVICE_VERSION,
372+
'operation' => self::SERVICE_NAME . 'Update',
373+
],
374+
];
375+
376+
$newPrices = [
377+
[
378+
'price' => 10.31,
379+
'price_type' => TierPriceInterface::PRICE_TYPE_FIXED,
380+
'website_id' => 0,
381+
'sku' => self::SIMPLE_PRODUCT_SKU,
382+
'customer_group' => self::CUSTOMER_ALL_GROUPS_NAME,
383+
'quantity' => 2
384+
],
385+
[
386+
'price' => 20.62,
387+
'price_type' => TierPriceInterface::PRICE_TYPE_FIXED,
388+
'website_id' => 1,
389+
'sku' => self::SIMPLE_PRODUCT_SKU,
390+
'customer_group' => self::CUSTOMER_ALL_GROUPS_NAME,
391+
'quantity' => 2
392+
]
393+
];
394+
395+
$response = $this->_webApiCall($serviceInfo, ['prices' => $newPrices]);
396+
$this->assertNotEmpty($response);
397+
$message = 'We found a duplicate website, tier price, customer group and quantity: '
398+
. 'Customer Group = %customerGroup, Website ID = %websiteId, Quantity = %qty. '
399+
. 'Row ID: SKU = %SKU, Website ID: %websiteId, Customer Group: %customerGroup, Quantity: %qty.';
400+
$this->assertEquals($message, $response[0]['message']);
401+
$this->assertEquals('simple', $response[0]['parameters'][0]);
402+
}
403+
357404
/**
358405
* Check prise exists and is correct.
359406
*

0 commit comments

Comments
 (0)