@@ -105,7 +105,7 @@ public function execute(array $entityIds = [], $useTempTable = false)
105
105
* @throws \Exception if metadataPool doesn't contain metadata for ProductInterface
106
106
* @throws \DomainException
107
107
*/
108
- private function getProductIdsWithParents (array $ childProductIds )
108
+ private function getProductIdsWithParents (array $ childProductIds ): array
109
109
{
110
110
/** @var \Magento\Framework\EntityManager\EntityMetadataInterface $metadata */
111
111
$ metadata = $ this ->metadataPool ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class);
@@ -123,8 +123,12 @@ private function getProductIdsWithParents(array $childProductIds)
123
123
);
124
124
125
125
$ parentProductIds = $ this ->connection ->fetchCol ($ select );
126
+ $ ids = array_unique (array_merge ($ childProductIds , $ parentProductIds ));
127
+ foreach ($ ids as $ key => $ id ) {
128
+ $ ids [$ key ] = (int ) $ id ;
129
+ }
126
130
127
- return array_unique ( array_merge ( $ childProductIds , $ parentProductIds )) ;
131
+ return $ ids ;
128
132
}
129
133
130
134
/**
@@ -175,7 +179,7 @@ protected function removeEntries()
175
179
protected function getNonAnchorCategoriesSelect (\Magento \Store \Model \Store $ store )
176
180
{
177
181
$ select = parent ::getNonAnchorCategoriesSelect ($ store );
178
- return $ select ->where ('ccp.product_id IN (?) OR relation.child_id IN (?) ' , $ this ->limitationByProducts );
182
+ return $ select ->where ('ccp.product_id IN (?) ' , $ this ->limitationByProducts );
179
183
}
180
184
181
185
/**
@@ -216,28 +220,28 @@ protected function isRangingNeeded()
216
220
* Returns a list of category ids which are assigned to product ids in the index
217
221
*
218
222
* @param array $productIds
219
- * @return \Magento\Framework\Indexer\CacheContext
223
+ * @return array
220
224
*/
221
- private function getCategoryIdsFromIndex (array $ productIds )
225
+ private function getCategoryIdsFromIndex (array $ productIds ): array
222
226
{
223
227
$ categoryIds = [];
224
228
foreach ($ this ->storeManager ->getStores () as $ store ) {
225
- $ categoryIds = array_merge (
226
- $ categoryIds ,
227
- $ this ->connection ->fetchCol (
228
- $ this ->connection ->select ()
229
- ->from ($ this ->getIndexTable ($ store ->getId ()), ['category_id ' ])
230
- ->where ('product_id IN (?) ' , $ productIds )
231
- ->distinct ()
232
- )
229
+ $ storeCategories = $ this ->connection ->fetchCol (
230
+ $ this ->connection ->select ()
231
+ ->from ($ this ->getIndexTable ($ store ->getId ()), ['category_id ' ])
232
+ ->where ('product_id IN (?) ' , $ productIds )
233
+ ->distinct ()
233
234
);
235
+ $ categoryIds [] = $ storeCategories ;
234
236
}
235
- $ parentCategories = $ categoryIds ;
237
+ $ categoryIds = array_merge (...$ categoryIds );
238
+
239
+ $ parentCategories = [$ categoryIds ];
236
240
foreach ($ categoryIds as $ categoryId ) {
237
241
$ parentIds = explode ('/ ' , $ this ->getPathFromCategoryId ($ categoryId ));
238
- $ parentCategories = array_merge ( $ parentCategories , $ parentIds) ;
242
+ $ parentCategories[] = $ parentIds ;
239
243
}
240
- $ categoryIds = array_unique ($ parentCategories );
244
+ $ categoryIds = array_unique (array_merge (... $ parentCategories) );
241
245
242
246
return $ categoryIds ;
243
247
}
0 commit comments