Skip to content

Commit bdc341f

Browse files
committed
AC-6810: Catalog Price Rule single product reindex works incorrectly - 02
1 parent 9ad7f4a commit bdc341f

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ public function executeRow($id)
133133
* Execute partial indexation by ID. Template method
134134
*
135135
* @param int $id
136+
* @throws \Magento\Framework\Exception\LocalizedException
136137
* @return void
137-
*@throws \Magento\Framework\Exception\LocalizedException
138138
*/
139-
abstract protected function doExecuteRow(int $id);
139+
abstract protected function doExecuteRow($id);
140140

141141
/**
142142
* Get cache manager

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

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

87
namespace Magento\CatalogRule\Model\Indexer;
98

@@ -43,7 +42,6 @@ class IndexBuilder
4342
* @var \Magento\Framework\EntityManager\MetadataPool
4443
* @deprecated 101.0.0
4544
* @since 100.1.0
46-
* @see Not used anymore
4745
*/
4846
protected $metadataPool;
4947

@@ -54,7 +52,6 @@ class IndexBuilder
5452
*
5553
* @var array
5654
* @deprecated 101.0.0
57-
* @see Not used anymore
5855
*/
5956
protected $_catalogRuleGroupWebsiteColumnsList = ['rule_id', 'customer_group_id', 'website_id'];
6057

@@ -260,23 +257,20 @@ public function __construct(
260257
* Reindex by id
261258
*
262259
* @param int $id
260+
* @throws LocalizedException
263261
* @return void
264-
*@throws LocalizedException
265262
*/
266-
public function reindexById(int $id)
263+
public function reindexById($id)
267264
{
268265
try {
269266
$this->cleanProductIndex([$id]);
270267

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

277-
$this->cleanProductPriceIndex([$id]);
278-
$this->reindexRuleProductPrice->execute($this->batchCount, $id);
279-
280274
$this->reindexRuleGroupWebsite->execute();
281275
} catch (\Exception $e) {
282276
$this->critical($e);
@@ -492,6 +486,28 @@ protected function applyRule(Rule $rule, $product)
492486
return $this;
493487
}
494488

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+
495511
/**
496512
* Retrieve table name
497513
*

app/code/Magento/CatalogRule/Model/Indexer/Product/ProductRuleIndexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function doExecuteList($ids)
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
protected function doExecuteRow(int $id)
24+
protected function doExecuteRow($id)
2525
{
2626
$this->indexBuilder->reindexById($id);
2727
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function doExecuteList($ids)
2525
*
2626
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2727
*/
28-
protected function doExecuteRow(int $id)
28+
protected function doExecuteRow($id)
2929
{
3030
$this->indexBuilder->reindexFull();
3131
}

0 commit comments

Comments
 (0)