1616use Magento \Framework \Exception \LocalizedException ;
1717use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
1818use 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 ;
1924
2025/**
2126 * Validate Tier Price and check duplication
@@ -91,6 +96,11 @@ class TierPriceValidator implements ResetAfterRequestInterface
9196 */
9297 private $ productsCacheBySku = [];
9398
99+ /**
100+ * @var ScopeConfigInterface
101+ */
102+ private $ scopeConfig ;
103+
94104 /**
95105 * TierPriceValidator constructor.
96106 *
@@ -103,17 +113,20 @@ class TierPriceValidator implements ResetAfterRequestInterface
103113 * @param InvalidSkuProcessor $invalidSkuProcessor
104114 * @param ProductRepositoryInterface $productRepository
105115 * @param array $allowedProductTypes [optional]
116+ * @param ScopeConfigInterface|null $scopeConfig
117+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
106118 */
107119 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 ,
115127 ProductRepositoryInterface $ productRepository ,
116- array $ allowedProductTypes = []
128+ array $ allowedProductTypes = [],
129+ ?ScopeConfigInterface $ scopeConfig = null
117130 ) {
118131 $ this ->productIdLocator = $ productIdLocator ;
119132 $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
@@ -124,6 +137,7 @@ public function __construct(
124137 $ this ->invalidSkuProcessor = $ invalidSkuProcessor ;
125138 $ this ->productRepository = $ productRepository ;
126139 $ this ->allowedProductTypes = $ allowedProductTypes ;
140+ $ this ->scopeConfig = $ scopeConfig ?: ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
127141 }
128142
129143 /**
@@ -355,10 +369,19 @@ private function checkQuantity(TierPriceInterface $price, $key, Result $validati
355369 * @param Result $validationResult
356370 * @return void
357371 */
358- private function checkWebsite (TierPriceInterface $ price , $ key , Result $ validationResult )
372+ private function checkWebsite (TierPriceInterface $ price , $ key , Result $ validationResult ): void
359373 {
360374 try {
361375 $ 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+ }
362385 } catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
363386 $ validationResult ->addFailedItem (
364387 $ key ,
0 commit comments