Skip to content

Commit 1a4efd5

Browse files
author
Bohdan Berezhniy
committed
14008-use-default-stores-for-rule-validation
1 parent 26391b5 commit 1a4efd5

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

Model/ProductLabelAction.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

view/adminhtml/web/js/grid/provider.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ define([
2525
$.extend(params, temp);
2626
});
2727
$.extend(this.params, conditions);
28-
28+
2929
$.extend(this.params, {
30-
'website_ids' : $('[name=website_ids]').val(),
31-
'catalog_price_rule_ids' : $('[name=catalog_price_rule_ids]').val(),
30+
'store_ids' : $('[name=store_ids]').val(),
3231
'apply_by' : $('[name=apply_by]').val(),
3332
'display_on_parent' : $('[name=display_on_parent]').val()
3433
});

0 commit comments

Comments
 (0)