@@ -235,18 +235,7 @@ public function getListProductIds($rule, array $params = []): array
235235 $ conditions = $ rule ->getConditions ();
236236
237237 if (!empty ($ conditions ['conditions ' ])) {
238- if ($ rule ->getWebsiteIds ()) {
239- $ storeIds = [];
240- $ websites = $ this ->getWebsitesMap ->execute ();
241- foreach ($ websites as $ websiteId => $ defaultStoreId ) {
242- if (in_array ($ websiteId , $ rule ->getWebsiteIds ())) {
243- $ storeIds [] = $ defaultStoreId ;
244- }
245- }
246- } else {
247- $ storeIds = [0 ];
248- }
249-
238+ $ storeIds = $ this ->getDefaultStoreIds ($ rule );
250239 $ conditions = $ rule ->getConditions ()->asArray ();
251240
252241 if ($ this ->validationFilter !== null ) {
@@ -327,4 +316,39 @@ protected function isRuleWilBeAppliedForSpecificProduct(array $params): bool
327316 {
328317 return $ params && isset ($ params ['rule_apply_type ' ]) && ($ params ['rule_apply_type ' ] == ApplyByOptions::ON_PRODUCT_SAVE );
329318 }
319+
320+ /**
321+ * @param $rule
322+ * @return array
323+ * @throws \Magento\Framework\Exception\NoSuchEntityException
324+ */
325+ private function getDefaultStoreIds ($ rule ): array
326+ {
327+ $ defaultStoreIds = [];
328+
329+ $ storeIds = (array )$ rule ->getStoreIds ();
330+
331+ // [website_id => default_store_id]
332+ $ websiteIdToDefaultStoreIdMap = $ this ->getWebsitesMap ->execute ();
333+
334+ if (in_array (0 , $ storeIds )) {
335+ $ defaultStoreIds = $ websiteIdToDefaultStoreIdMap ;
336+ } else {
337+ $ storeManager = \Magento \Framework \App \ObjectManager::getInstance ()->get (\Magento \Store \Model \StoreManagerInterface::class);
338+
339+ foreach ($ storeIds as $ id ) {
340+
341+ $ websiteId = $ storeManager ->getStore ($ id )->getWebsiteId ();
342+ $ websiteIds [$ websiteId ] = $ websiteId ;
343+ }
344+
345+ foreach ($ websiteIds as $ websiteId ) {
346+ if (isset ($ websiteIdToDefaultStoreIdMap [$ websiteId ])) {
347+ $ defaultStoreIds [] = $ websiteIdToDefaultStoreIdMap [$ websiteId ];
348+ }
349+ }
350+ }
351+
352+ return $ defaultStoreIds ;
353+ }
330354}
0 commit comments