Skip to content

Commit 2d3cf62

Browse files
committed
MAGE-1244: fix logic
1 parent 926e0f3 commit 2d3cf62

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

Model/Indexer/Category.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
class Category implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
1414
{
15+
public static $affectedProductIds = [];
16+
1517
public function __construct(
1618
protected StoreManagerInterface $storeManager,
1719
protected ConfigHelper $configHelper,
@@ -41,6 +43,9 @@ public function executeList(array $ids)
4143

4244
public function executeRow($id)
4345
{
46+
if (count(self::$affectedProductIds)) {
47+
$this->categoryBatchQueueProcessor->setAffectedProductIds(self::$affectedProductIds);
48+
}
4449
$this->execute([$id]);
4550
}
4651
}

Service/Category/BatchQueueProcessor.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
use Algolia\AlgoliaSearch\Service\AlgoliaCredentialsManager;
1212
use Algolia\AlgoliaSearch\Service\Category\IndexBuilder as CategoryIndexBuilder;
1313
use Algolia\AlgoliaSearch\Service\Product\IndexBuilder as ProductIndexBuilder;
14+
use Magento\Framework\Exception\LocalizedException;
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516

1617
class BatchQueueProcessor implements BatchQueueProcessorInterface
1718
{
18-
public static $affectedProductIds = [];
19+
public $affectedProductIds = [];
1920

2021
public function __construct(
2122
protected Data $dataHelper,
@@ -29,7 +30,7 @@ public function __construct(
2930
* @param int $storeId
3031
* @param array|null $entityIds
3132
* @return void
32-
* @throws NoSuchEntityException
33+
* @throws NoSuchEntityException|LocalizedException
3334
*/
3435
public function processBatch(int $storeId, ?array $entityIds = null): void
3536
{
@@ -43,7 +44,9 @@ public function processBatch(int $storeId, ?array $entityIds = null): void
4344
return;
4445
}
4546

46-
$this->rebuildAffectedProducts($storeId);
47+
if (count($this->affectedProductIds) > 0) {
48+
$this->rebuildAffectedProducts($storeId);
49+
}
4750

4851
$categoriesPerPage = $this->configHelper->getNumberOfElementByPage();
4952

@@ -59,14 +62,11 @@ public function processBatch(int $storeId, ?array $entityIds = null): void
5962
/**
6063
* @param int $storeId
6164
*/
62-
protected function rebuildAffectedProducts($storeId)
65+
protected function rebuildAffectedProducts(int $storeId): void
6366
{
64-
$affectedProducts = self::$affectedProductIds;
65-
$affectedProductsCount = count($affectedProducts);
66-
67-
if ($affectedProductsCount > 0 && $this->configHelper->indexProductOnCategoryProductsUpdate($storeId)) {
67+
if ($this->configHelper->indexProductOnCategoryProductsUpdate($storeId)) {
6868
$productsPerPage = $this->configHelper->getNumberOfElementByPage();
69-
foreach (array_chunk($affectedProducts, $productsPerPage) as $chunk) {
69+
foreach (array_chunk($this->affectedProductIds, $productsPerPage) as $chunk) {
7070
/** @uses ProductIndexBuilder::buildIndexList() */
7171
$this->queue->addToQueue(
7272
ProductIndexBuilder::class,
@@ -86,7 +86,7 @@ protected function rebuildAffectedProducts($storeId)
8686
* @param int $categoriesPerPage
8787
* @param int $storeId
8888
*/
89-
protected function processSpecificCategories($categoryIds, $categoriesPerPage, $storeId)
89+
protected function processSpecificCategories(array $categoryIds, int $categoriesPerPage, int $storeId): void
9090
{
9191
foreach (array_chunk($categoryIds, $categoriesPerPage) as $chunk) {
9292
/** @uses CategoryIndexBuilder::buildIndexList */
@@ -106,10 +106,10 @@ protected function processSpecificCategories($categoryIds, $categoriesPerPage, $
106106
* @param int $storeId
107107
* @param int $categoriesPerPage
108108
*
109-
* @throws Magento\Framework\Exception\LocalizedException
110-
* @throws Magento\Framework\Exception\NoSuchEntityException
109+
* @throws NoSuchEntityException
110+
* @throws LocalizedException
111111
*/
112-
protected function processFullReindex($storeId, $categoriesPerPage)
112+
protected function processFullReindex(int $storeId, int $categoriesPerPage): void
113113
{
114114
/** @uses IndicesConfigurator::saveConfigurationToAlgolia() */
115115
$this->queue->addToQueue(IndicesConfigurator::class, 'saveConfigurationToAlgolia', ['storeId' => $storeId]);
@@ -138,4 +138,13 @@ protected function processFullReindex($storeId, $categoriesPerPage)
138138
);
139139
}
140140
}
141+
142+
/**
143+
* @param array $affectedProductIds
144+
* @return void
145+
*/
146+
public function setAffectedProductIds(array $affectedProductIds): void
147+
{
148+
$this->affectedProductIds = $affectedProductIds;
149+
}
141150
}

0 commit comments

Comments
 (0)