2020use Magento \Catalog \Helper \Data ;
2121use Magento \Store \Model \ScopeInterface ;
2222use 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 }
0 commit comments