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