11
11
use Algolia \AlgoliaSearch \Service \AlgoliaCredentialsManager ;
12
12
use Algolia \AlgoliaSearch \Service \Category \IndexBuilder as CategoryIndexBuilder ;
13
13
use Algolia \AlgoliaSearch \Service \Product \IndexBuilder as ProductIndexBuilder ;
14
- use Magento \Framework \Exception \LocalizedException ;
15
14
use Magento \Framework \Exception \NoSuchEntityException ;
16
15
17
16
class BatchQueueProcessor implements BatchQueueProcessorInterface
18
17
{
19
- public $ affectedProductIds = [];
18
+ public static $ affectedProductIds = [];
20
19
21
20
public function __construct (
22
21
protected Data $ dataHelper ,
@@ -30,7 +29,7 @@ public function __construct(
30
29
* @param int $storeId
31
30
* @param array|null $entityIds
32
31
* @return void
33
- * @throws NoSuchEntityException|LocalizedException
32
+ * @throws NoSuchEntityException
34
33
*/
35
34
public function processBatch (int $ storeId , ?array $ entityIds = null ): void
36
35
{
@@ -44,9 +43,7 @@ public function processBatch(int $storeId, ?array $entityIds = null): void
44
43
return ;
45
44
}
46
45
47
- if (count ($ this ->affectedProductIds ) > 0 ) {
48
- $ this ->rebuildAffectedProducts ($ storeId );
49
- }
46
+ $ this ->rebuildAffectedProducts ($ storeId );
50
47
51
48
$ categoriesPerPage = $ this ->configHelper ->getNumberOfElementByPage ();
52
49
@@ -62,11 +59,14 @@ public function processBatch(int $storeId, ?array $entityIds = null): void
62
59
/**
63
60
* @param int $storeId
64
61
*/
65
- protected function rebuildAffectedProducts (int $ storeId ): void
62
+ protected function rebuildAffectedProducts ($ storeId )
66
63
{
67
- if ($ this ->configHelper ->indexProductOnCategoryProductsUpdate ($ storeId )) {
64
+ $ affectedProducts = self ::$ affectedProductIds ;
65
+ $ affectedProductsCount = count ($ affectedProducts );
66
+
67
+ if ($ affectedProductsCount > 0 && $ this ->configHelper ->indexProductOnCategoryProductsUpdate ($ storeId )) {
68
68
$ productsPerPage = $ this ->configHelper ->getNumberOfElementByPage ();
69
- foreach (array_chunk ($ this -> affectedProductIds , $ productsPerPage ) as $ chunk ) {
69
+ foreach (array_chunk ($ affectedProducts , $ productsPerPage ) as $ chunk ) {
70
70
/** @uses ProductIndexBuilder::buildIndexList() */
71
71
$ this ->queue ->addToQueue (
72
72
ProductIndexBuilder::class,
@@ -86,7 +86,7 @@ protected function rebuildAffectedProducts(int $storeId): void
86
86
* @param int $categoriesPerPage
87
87
* @param int $storeId
88
88
*/
89
- protected function processSpecificCategories (array $ categoryIds , int $ categoriesPerPage , int $ storeId ): void
89
+ protected function processSpecificCategories ($ categoryIds , $ categoriesPerPage , $ storeId )
90
90
{
91
91
foreach (array_chunk ($ categoryIds , $ categoriesPerPage ) as $ chunk ) {
92
92
/** @uses CategoryIndexBuilder::buildIndexList */
@@ -106,10 +106,10 @@ protected function processSpecificCategories(array $categoryIds, int $categories
106
106
* @param int $storeId
107
107
* @param int $categoriesPerPage
108
108
*
109
- * @throws NoSuchEntityException
110
- * @throws LocalizedException
109
+ * @throws Magento\Framework\Exception\LocalizedException
110
+ * @throws Magento\Framework\Exception\NoSuchEntityException
111
111
*/
112
- protected function processFullReindex (int $ storeId , int $ categoriesPerPage ): void
112
+ protected function processFullReindex ($ storeId , $ categoriesPerPage )
113
113
{
114
114
/** @uses IndicesConfigurator::saveConfigurationToAlgolia() */
115
115
$ this ->queue ->addToQueue (IndicesConfigurator::class, 'saveConfigurationToAlgolia ' , ['storeId ' => $ storeId ]);
@@ -138,13 +138,4 @@ protected function processFullReindex(int $storeId, int $categoriesPerPage): voi
138
138
);
139
139
}
140
140
}
141
-
142
- /**
143
- * @param array $affectedProductIds
144
- * @return void
145
- */
146
- public function setAffectedProductIds (array $ affectedProductIds ): void
147
- {
148
- $ this ->affectedProductIds = $ affectedProductIds ;
149
- }
150
141
}
0 commit comments