Skip to content

Commit 84b9e96

Browse files
committed
Merge remote-tracking branch 'AC-6810-v1/fix-issue-36049' into AC-6810
2 parents 24a2c46 + f8598f4 commit 84b9e96

File tree

4 files changed

+52
-53
lines changed

4 files changed

+52
-53
lines changed

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\CatalogRule\Model\Indexer;
89

@@ -42,6 +43,7 @@ class IndexBuilder
4243
* @var \Magento\Framework\EntityManager\MetadataPool
4344
* @deprecated 101.0.0
4445
* @since 100.1.0
46+
* @see Not used anymore
4547
*/
4648
protected $metadataPool;
4749

@@ -52,6 +54,7 @@ class IndexBuilder
5254
*
5355
* @var array
5456
* @deprecated 101.0.0
57+
* @see Not used anymore
5558
*/
5659
protected $_catalogRuleGroupWebsiteColumnsList = ['rule_id', 'customer_group_id', 'website_id'];
5760

@@ -265,12 +268,15 @@ public function reindexById($id)
265268
try {
266269
$this->cleanProductIndex([$id]);
267270

268-
$products = $this->productLoader->getProducts([$id]);
269271
$activeRules = $this->getActiveRules();
270-
foreach ($products as $product) {
271-
$this->applyRules($activeRules, $product);
272+
foreach ($activeRules as $rule) {
273+
$rule->setProductsFilter([$id]);
274+
$this->reindexRuleProduct->execute($rule, $this->batchCount);
272275
}
273276

277+
$this->cleanProductPriceIndex([$id]);
278+
$this->reindexRuleProductPrice->execute($this->batchCount, $id);
279+
274280
$this->reindexRuleGroupWebsite->execute();
275281
} catch (\Exception $e) {
276282
$this->critical($e);
@@ -486,28 +492,6 @@ protected function applyRule(Rule $rule, $product)
486492
return $this;
487493
}
488494

489-
/**
490-
* Apply rules
491-
*
492-
* @param RuleCollection $ruleCollection
493-
* @param Product $product
494-
* @return void
495-
*/
496-
private function applyRules(RuleCollection $ruleCollection, Product $product): void
497-
{
498-
foreach ($ruleCollection as $rule) {
499-
if (!$rule->validate($product)) {
500-
continue;
501-
}
502-
503-
$websiteIds = array_intersect($product->getWebsiteIds(), $rule->getWebsiteIds());
504-
$this->assignProductToRule($rule, $product->getId(), $websiteIds);
505-
}
506-
507-
$this->cleanProductPriceIndex([$product->getId()]);
508-
$this->reindexRuleProductPrice->execute($this->batchCount, $product->getId());
509-
}
510-
511495
/**
512496
* Retrieve table name
513497
*

app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProduct.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\CatalogRule\Model\Indexer;
89

@@ -124,7 +125,7 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
124125
: $toTimeInAdminTz;
125126

126127
foreach ($productIds as $productId => $validationByWebsite) {
127-
if (!isset($validationByWebsite[$websiteId]) || $validationByWebsite[$websiteId] === null) {
128+
if (empty($validationByWebsite[$websiteId])) {
128129
continue;
129130
}
130131

app/code/Magento/CatalogRule/Model/Rule.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\CatalogRule\Model;
79

810
use Magento\Catalog\Model\Product;
@@ -13,6 +15,7 @@
1315
use Magento\CatalogRule\Helper\Data;
1416
use Magento\CatalogRule\Model\Data\Condition\Converter;
1517
use Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor;
18+
use Magento\CatalogRule\Model\ResourceModel\Product\ConditionsToCollectionApplier;
1619
use Magento\CatalogRule\Model\ResourceModel\Rule as RuleResourceModel;
1720
use Magento\CatalogRule\Model\Rule\Action\CollectionFactory as RuleCollectionFactory;
1821
use Magento\CatalogRule\Model\Rule\Condition\CombineFactory;
@@ -33,7 +36,6 @@
3336
use Magento\Framework\Stdlib\DateTime;
3437
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
3538
use Magento\Store\Model\StoreManagerInterface;
36-
use Magento\CatalogRule\Model\ResourceModel\Product\ConditionsToCollectionApplier;
3739

3840
/**
3941
* Catalog Rule data model
@@ -95,7 +97,7 @@ class Rule extends \Magento\Rule\Model\AbstractModel implements RuleInterface, I
9597
protected static $_priceRulesData = [];
9698

9799
/**
98-
* Catalog rule data
100+
* Catalog rule data class
99101
*
100102
* @var \Magento\CatalogRule\Helper\Data
101103
*/
@@ -348,6 +350,7 @@ public function getMatchingProductIds()
348350
if ($this->getWebsiteIds()) {
349351
/** @var $productCollection \Magento\Catalog\Model\ResourceModel\Product\Collection */
350352
$productCollection = $this->_productCollectionFactory->create();
353+
$productCollection->setStoreId($this->_storeManager->getDefaultStoreView()->getId());
351354
$productCollection->addWebsiteFilter($this->getWebsiteIds());
352355
if ($this->_productsFilter) {
353356
$productCollection->addIdFilter($this->_productsFilter);
@@ -879,6 +882,7 @@ public function setExtensionAttributes(RuleExtensionInterface $extensionAttribut
879882
*
880883
* @return Data\Condition\Converter
881884
* @deprecated 100.1.0
885+
* @see getRuleCondition, setRuleCondition
882886
*/
883887
private function getRuleConditionConverter()
884888
{

app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/ReindexRuleProductTest.php

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -318,30 +318,6 @@ public function executeDataProvider(): array
318318
'action_amount' => 43,
319319
'action_stop' => true,
320320
'sort_order' => 1
321-
],
322-
[
323-
'rule_id' => 100,
324-
'from_time' => 1498028400,
325-
'to_time' => 1498892399,
326-
'website_id' => 3,
327-
'customer_group_id' => 10,
328-
'product_id' => 3,
329-
'action_operator' => 'simple_action',
330-
'action_amount' => 43,
331-
'action_stop' => true,
332-
'sort_order' => 1
333-
],
334-
[
335-
'rule_id' => 100,
336-
'from_time' => 1498028400,
337-
'to_time' => 1498892399,
338-
'website_id' => 3,
339-
'customer_group_id' => 20,
340-
'product_id' => 3,
341-
'action_operator' => 'simple_action',
342-
'action_amount' => 43,
343-
'action_stop' => true,
344-
'sort_order' => 1
345321
]
346322
]
347323
],
@@ -412,7 +388,41 @@ public function executeDataProvider(): array
412388
'sort_order' => 1
413389
]
414390
]
415-
]
391+
],
392+
[
393+
[1, 2, 3],
394+
[
395+
1 => [1 => true],
396+
2 => [2 => true],
397+
3 => [3 => false]
398+
],
399+
[
400+
[
401+
'rule_id' => 100,
402+
'from_time' => 1498028400,
403+
'to_time' => 1498892399,
404+
'website_id' => 1,
405+
'customer_group_id' => 20,
406+
'product_id' => 1,
407+
'action_operator' => 'simple_action',
408+
'action_amount' => 43,
409+
'action_stop' => true,
410+
'sort_order' => 1
411+
],
412+
[
413+
'rule_id' => 100,
414+
'from_time' => 1498028400,
415+
'to_time' => 1498892399,
416+
'website_id' => 2,
417+
'customer_group_id' => 20,
418+
'product_id' => 2,
419+
'action_operator' => 'simple_action',
420+
'action_amount' => 43,
421+
'action_stop' => true,
422+
'sort_order' => 1
423+
]
424+
]
425+
]
416426
];
417427
}
418428

0 commit comments

Comments
 (0)