16
16
use Magento \Framework \Exception \LocalizedException ;
17
17
use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
18
18
use Magento \Store \Api \WebsiteRepositoryInterface ;
19
+ use Magento \Framework \App \ObjectManager ;
20
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
21
+ use Magento \Catalog \Helper \Data ;
22
+ use Magento \Store \Model \ScopeInterface ;
23
+ use Magento \Framework \Exception \NoSuchEntityException ;
19
24
20
25
/**
21
26
* Validate Tier Price and check duplication
@@ -91,6 +96,11 @@ class TierPriceValidator implements ResetAfterRequestInterface
91
96
*/
92
97
private $ productsCacheBySku = [];
93
98
99
+ /**
100
+ * @var ScopeConfigInterface
101
+ */
102
+ private $ scopeConfig ;
103
+
94
104
/**
95
105
* TierPriceValidator constructor.
96
106
*
@@ -103,17 +113,20 @@ class TierPriceValidator implements ResetAfterRequestInterface
103
113
* @param InvalidSkuProcessor $invalidSkuProcessor
104
114
* @param ProductRepositoryInterface $productRepository
105
115
* @param array $allowedProductTypes [optional]
116
+ * @param ScopeConfigInterface|null $scopeConfig
117
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
106
118
*/
107
119
public function __construct (
108
- ProductIdLocatorInterface $ productIdLocator ,
109
- SearchCriteriaBuilder $ searchCriteriaBuilder ,
110
- FilterBuilder $ filterBuilder ,
111
- GroupRepositoryInterface $ customerGroupRepository ,
112
- WebsiteRepositoryInterface $ websiteRepository ,
113
- Result $ validationResult ,
114
- InvalidSkuProcessor $ invalidSkuProcessor ,
120
+ ProductIdLocatorInterface $ productIdLocator ,
121
+ SearchCriteriaBuilder $ searchCriteriaBuilder ,
122
+ FilterBuilder $ filterBuilder ,
123
+ GroupRepositoryInterface $ customerGroupRepository ,
124
+ WebsiteRepositoryInterface $ websiteRepository ,
125
+ Result $ validationResult ,
126
+ InvalidSkuProcessor $ invalidSkuProcessor ,
115
127
ProductRepositoryInterface $ productRepository ,
116
- array $ allowedProductTypes = []
128
+ array $ allowedProductTypes = [],
129
+ ?ScopeConfigInterface $ scopeConfig = null
117
130
) {
118
131
$ this ->productIdLocator = $ productIdLocator ;
119
132
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
@@ -124,6 +137,7 @@ public function __construct(
124
137
$ this ->invalidSkuProcessor = $ invalidSkuProcessor ;
125
138
$ this ->productRepository = $ productRepository ;
126
139
$ this ->allowedProductTypes = $ allowedProductTypes ;
140
+ $ this ->scopeConfig = $ scopeConfig ?: ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
127
141
}
128
142
129
143
/**
@@ -355,10 +369,19 @@ private function checkQuantity(TierPriceInterface $price, $key, Result $validati
355
369
* @param Result $validationResult
356
370
* @return void
357
371
*/
358
- private function checkWebsite (TierPriceInterface $ price , $ key , Result $ validationResult )
372
+ private function checkWebsite (TierPriceInterface $ price , $ key , Result $ validationResult ): void
359
373
{
360
374
try {
361
375
$ this ->websiteRepository ->getById ($ price ->getWebsiteId ());
376
+ $ isWebsiteScope = $ this ->scopeConfig
377
+ ->isSetFlag (
378
+ Data::XML_PATH_PRICE_SCOPE ,
379
+ ScopeInterface::SCOPE_STORE ,
380
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT
381
+ );
382
+ if (!$ isWebsiteScope && (int ) $ this ->allWebsitesValue !== $ price ->getWebsiteId ()) {
383
+ throw NoSuchEntityException::singleField ('website_id ' , $ price ->getWebsiteId ());
384
+ }
362
385
} catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
363
386
$ validationResult ->addFailedItem (
364
387
$ key ,
0 commit comments