Skip to content

Commit cc95579

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4334' into PR_2025_12_03_chittima
2 parents 62a00bc + 64eb4d6 commit cc95579

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Catalog\Helper\Data;
2121
use Magento\Store\Model\ScopeInterface;
2222
use Magento\Framework\Exception\NoSuchEntityException;
23+
use Magento\Store\Model\StoreManagerInterface;
2324

2425
/**
2526
* Validate Tier Price and check duplication
@@ -88,6 +89,11 @@ class TierPriceValidator implements ResetAfterRequestInterface
8889
*/
8990
private $scopeConfig;
9091

92+
/**
93+
* @var StoreManagerInterface
94+
*/
95+
private StoreManagerInterface $storeManager;
96+
9197
/**
9298
* TierPriceValidator constructor.
9399
*
@@ -99,6 +105,7 @@ class TierPriceValidator implements ResetAfterRequestInterface
99105
* @param array $allowedProductTypes [optional]
100106
* @param ResourceConnection|null $resourceConnection
101107
* @param ScopeConfigInterface|null $scopeConfig
108+
* @param StoreManagerInterface|null $storeManager
102109
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
103110
*/
104111
public function __construct(
@@ -109,7 +116,8 @@ public function __construct(
109116
ProductRepositoryInterface $productRepository,
110117
array $allowedProductTypes = [],
111118
?ResourceConnection $resourceConnection = null,
112-
?ScopeConfigInterface $scopeConfig = null
119+
?ScopeConfigInterface $scopeConfig = null,
120+
?StoreManagerInterface $storeManager = null
113121
) {
114122
$this->productIdLocator = $productIdLocator;
115123
$this->websiteRepository = $websiteRepository;
@@ -119,6 +127,7 @@ public function __construct(
119127
$this->allowedProductTypes = $allowedProductTypes;
120128
$this->resourceConnection = $resourceConnection ?: ObjectManager::getInstance()->get(ResourceConnection::class);
121129
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
130+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
122131
}
123132

124133
/**
@@ -354,12 +363,12 @@ private function checkWebsite(TierPriceInterface $price, $key, Result $validatio
354363
{
355364
try {
356365
$this->websiteRepository->getById($price->getWebsiteId());
357-
$isWebsiteScope = $this->scopeConfig
358-
->isSetFlag(
359-
Data::XML_PATH_PRICE_SCOPE,
360-
ScopeInterface::SCOPE_STORE,
361-
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
362-
);
366+
$defaultStoreView = $this->storeManager->getDefaultStoreView();
367+
$isWebsiteScope = $this->scopeConfig->isSetFlag(
368+
Data::XML_PATH_PRICE_SCOPE,
369+
ScopeInterface::SCOPE_STORE,
370+
$defaultStoreView->getCode()
371+
);
363372
if (!$isWebsiteScope && (int) $this->allWebsitesValue !== $price->getWebsiteId()) {
364373
throw NoSuchEntityException::singleField('website_id', $price->getWebsiteId());
365374
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Price/Validation/TierPriceValidatorTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
use Magento\Framework\DB\Select;
2020
use Magento\Framework\Exception\NoSuchEntityException;
2121
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
22+
use Magento\Store\Api\Data\StoreInterface;
2223
use Magento\Store\Api\Data\WebsiteInterface;
2324
use Magento\Store\Api\WebsiteRepositoryInterface;
25+
use Magento\Store\Model\StoreManagerInterface;
2426
use PHPUnit\Framework\MockObject\MockObject;
2527
use PHPUnit\Framework\TestCase;
2628

@@ -76,6 +78,11 @@ class TierPriceValidatorTest extends TestCase
7678
*/
7779
private $adapterInterface;
7880

81+
/**
82+
* @var StoreManagerInterface|MockObject
83+
*/
84+
private StoreManagerInterface $storeManager;
85+
7986
/**
8087
* {@inheritdoc}
8188
*/
@@ -107,6 +114,7 @@ protected function setUp(): void
107114
$this->adapterInterface = $this->getMockBuilder(AdapterInterface::class)
108115
->disableOriginalConstructor()
109116
->getMockForAbstractClass();
117+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
110118

111119
$objectManagerHelper = new ObjectManager($this);
112120
$this->tierPriceValidator = $objectManagerHelper->getObject(
@@ -117,7 +125,8 @@ protected function setUp(): void
117125
'validationResult' => $this->validationResult,
118126
'invalidSkuProcessor' => $this->invalidSkuProcessor,
119127
'productRepository' => $this->productRepository,
120-
'resourceConnection' => $this->resourceConnectionMock
128+
'resourceConnection' => $this->resourceConnectionMock,
129+
'storeManager' => $this->storeManager
121130
]
122131
);
123132
}
@@ -237,8 +246,12 @@ public function testValidateSkus()
237246
public function testRetrieveValidationResult(array $returned)
238247
{
239248
$sku = 'ASDF234234';
249+
$defaultStoreViewCode = 'default';
240250
$prices = [$this->tierPrice];
241251
$existingPrices = [$this->tierPrice];
252+
$defaultStoreView = $this->createMock(StoreInterface::class);
253+
$defaultStoreView->expects($this->once())->method('getCode')->willReturn($defaultStoreViewCode);
254+
$this->storeManager->expects($this->once())->method('getDefaultStoreView')->willReturn($defaultStoreView);
242255
$this->prepareRetrieveValidationResultMethod($sku, $returned);
243256
$website = $this->getMockBuilder(WebsiteInterface::class)
244257
->disableOriginalConstructor()

0 commit comments

Comments
 (0)