14
14
use Magento \Framework \Api \FilterBuilder ;
15
15
use Magento \Framework \Api \SearchCriteriaBuilder ;
16
16
use Magento \Framework \Exception \LocalizedException ;
17
- use Magento \Framework \Exception \NoSuchEntityException ;
18
17
use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
19
18
use Magento \Store \Api \WebsiteRepositoryInterface ;
20
19
use Magento \Framework \App \ObjectManager ;
20
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
21
21
use Magento \Catalog \Helper \Data ;
22
+ use Magento \Store \Model \ScopeInterface ;
23
+ use Magento \Framework \Exception \NoSuchEntityException ;
22
24
23
25
/**
24
26
* Validate Tier Price and check duplication
@@ -90,14 +92,14 @@ class TierPriceValidator implements ResetAfterRequestInterface
90
92
private $ productRepository ;
91
93
92
94
/**
93
- * @var Data
95
+ * @var array
94
96
*/
95
- private $ catalogData ;
97
+ private $ productsCacheBySku = [] ;
96
98
97
99
/**
98
- * @var array
100
+ * @var ScopeConfigInterface
99
101
*/
100
- private $ productsCacheBySku = [] ;
102
+ private $ scopeConfig ;
101
103
102
104
/**
103
105
* TierPriceValidator constructor.
@@ -111,7 +113,7 @@ class TierPriceValidator implements ResetAfterRequestInterface
111
113
* @param InvalidSkuProcessor $invalidSkuProcessor
112
114
* @param ProductRepositoryInterface $productRepository
113
115
* @param array $allowedProductTypes [optional]
114
- * @param Data |null $catalogData
116
+ * @param ScopeConfigInterface |null $scopeConfig
115
117
*/
116
118
public function __construct (
117
119
ProductIdLocatorInterface $ productIdLocator ,
@@ -123,7 +125,7 @@ public function __construct(
123
125
InvalidSkuProcessor $ invalidSkuProcessor ,
124
126
ProductRepositoryInterface $ productRepository ,
125
127
array $ allowedProductTypes = [],
126
- ?Data $ catalogData = null
128
+ ?ScopeConfigInterface $ scopeConfig = null
127
129
) {
128
130
$ this ->productIdLocator = $ productIdLocator ;
129
131
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
@@ -134,7 +136,7 @@ public function __construct(
134
136
$ this ->invalidSkuProcessor = $ invalidSkuProcessor ;
135
137
$ this ->productRepository = $ productRepository ;
136
138
$ this ->allowedProductTypes = $ allowedProductTypes ;
137
- $ this ->catalogData = $ catalogData ?: ObjectManager::getInstance ()->get (Data ::class);
139
+ $ this ->scopeConfig = $ scopeConfig ?: ObjectManager::getInstance ()->get (ScopeConfigInterface ::class);
138
140
}
139
141
140
142
/**
@@ -369,7 +371,12 @@ private function checkQuantity(TierPriceInterface $price, $key, Result $validati
369
371
private function checkWebsite (TierPriceInterface $ price , $ key , Result $ validationResult ): void
370
372
{
371
373
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 &&
373
380
isset ($ this ->productsCacheBySku [$ price ->getSku ()]) &&
374
381
is_array ($ this ->productsCacheBySku [$ price ->getSku ()]->getTierPrices ()) &&
375
382
count ($ this ->productsCacheBySku [$ price ->getSku ()]->getTierPrices ()) > 0 &&
@@ -378,7 +385,6 @@ private function checkWebsite(TierPriceInterface $price, $key, Result $validatio
378
385
// phpstan:ignore
379
386
throw NoSuchEntityException::singleField ('website_id ' , $ price ->getWebsiteId ());
380
387
}
381
- $ this ->websiteRepository ->getById ($ price ->getWebsiteId ());
382
388
} catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
383
389
$ validationResult ->addFailedItem (
384
390
$ key ,
0 commit comments