Skip to content

Commit 39d339c

Browse files
committed
ACP2E-2689: No Appropriate error message when website id is wrong in the request
- Fixed the build failure.
1 parent bf8d3c1 commit 39d339c

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
use Magento\Framework\Api\FilterBuilder;
1515
use Magento\Framework\Api\SearchCriteriaBuilder;
1616
use Magento\Framework\Exception\LocalizedException;
17-
use Magento\Framework\Exception\NoSuchEntityException;
1817
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1918
use Magento\Store\Api\WebsiteRepositoryInterface;
2019
use Magento\Framework\App\ObjectManager;
20+
use Magento\Framework\App\Config\ScopeConfigInterface;
2121
use Magento\Catalog\Helper\Data;
22+
use Magento\Store\Model\ScopeInterface;
23+
use Magento\Framework\Exception\NoSuchEntityException;
2224

2325
/**
2426
* Validate Tier Price and check duplication
@@ -90,14 +92,14 @@ class TierPriceValidator implements ResetAfterRequestInterface
9092
private $productRepository;
9193

9294
/**
93-
* @var Data
95+
* @var array
9496
*/
95-
private $catalogData;
97+
private $productsCacheBySku = [];
9698

9799
/**
98-
* @var array
100+
* @var ScopeConfigInterface
99101
*/
100-
private $productsCacheBySku = [];
102+
private $scopeConfig;
101103

102104
/**
103105
* TierPriceValidator constructor.
@@ -111,7 +113,7 @@ class TierPriceValidator implements ResetAfterRequestInterface
111113
* @param InvalidSkuProcessor $invalidSkuProcessor
112114
* @param ProductRepositoryInterface $productRepository
113115
* @param array $allowedProductTypes [optional]
114-
* @param Data|null $catalogData
116+
* @param ScopeConfigInterface|null $scopeConfig
115117
*/
116118
public function __construct(
117119
ProductIdLocatorInterface $productIdLocator,
@@ -123,7 +125,7 @@ public function __construct(
123125
InvalidSkuProcessor $invalidSkuProcessor,
124126
ProductRepositoryInterface $productRepository,
125127
array $allowedProductTypes = [],
126-
?Data $catalogData = null
128+
?ScopeConfigInterface $scopeConfig = null
127129
) {
128130
$this->productIdLocator = $productIdLocator;
129131
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
@@ -134,7 +136,7 @@ public function __construct(
134136
$this->invalidSkuProcessor = $invalidSkuProcessor;
135137
$this->productRepository = $productRepository;
136138
$this->allowedProductTypes = $allowedProductTypes;
137-
$this->catalogData = $catalogData ?: ObjectManager::getInstance()->get(Data::class);
139+
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
138140
}
139141

140142
/**
@@ -369,7 +371,12 @@ private function checkQuantity(TierPriceInterface $price, $key, Result $validati
369371
private function checkWebsite(TierPriceInterface $price, $key, Result $validationResult): void
370372
{
371373
try {
372-
if ($this->catalogData->isPriceGlobal() &&
374+
$this->websiteRepository->getById($price->getWebsiteId());
375+
$isGlobalConfig = (int) $this->scopeConfig->getValue(
376+
Data::XML_PATH_PRICE_SCOPE,
377+
ScopeInterface::SCOPE_STORE
378+
);
379+
if ($isGlobalConfig === Data::PRICE_SCOPE_GLOBAL &&
373380
isset($this->productsCacheBySku[$price->getSku()]) &&
374381
is_array($this->productsCacheBySku[$price->getSku()]->getTierPrices()) &&
375382
count($this->productsCacheBySku[$price->getSku()]->getTierPrices()) > 0 &&
@@ -378,7 +385,6 @@ private function checkWebsite(TierPriceInterface $price, $key, Result $validatio
378385
// phpstan:ignore
379386
throw NoSuchEntityException::singleField('website_id', $price->getWebsiteId());
380387
}
381-
$this->websiteRepository->getById($price->getWebsiteId());
382388
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
383389
$validationResult->addFailedItem(
384390
$key,

0 commit comments

Comments
 (0)