Skip to content

Commit 0e75b77

Browse files
committed
Merge remote-tracking branch 'magento-tango/MC-19652' into MPI-PR-10012019
2 parents 34a95ad + a14f7a9 commit 0e75b77

File tree

1 file changed

+20
-16
lines changed
  • app/code/Magento/Catalog/Model/Indexer/Product/Category/Action

1 file changed

+20
-16
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Category/Action/Rows.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function execute(array $entityIds = [], $useTempTable = false)
105105
* @throws \Exception if metadataPool doesn't contain metadata for ProductInterface
106106
* @throws \DomainException
107107
*/
108-
private function getProductIdsWithParents(array $childProductIds)
108+
private function getProductIdsWithParents(array $childProductIds): array
109109
{
110110
/** @var \Magento\Framework\EntityManager\EntityMetadataInterface $metadata */
111111
$metadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
@@ -123,8 +123,12 @@ private function getProductIdsWithParents(array $childProductIds)
123123
);
124124

125125
$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+
}
126130

127-
return array_unique(array_merge($childProductIds, $parentProductIds));
131+
return $ids;
128132
}
129133

130134
/**
@@ -175,7 +179,7 @@ protected function removeEntries()
175179
protected function getNonAnchorCategoriesSelect(\Magento\Store\Model\Store $store)
176180
{
177181
$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);
179183
}
180184

181185
/**
@@ -216,28 +220,28 @@ protected function isRangingNeeded()
216220
* Returns a list of category ids which are assigned to product ids in the index
217221
*
218222
* @param array $productIds
219-
* @return \Magento\Framework\Indexer\CacheContext
223+
* @return array
220224
*/
221-
private function getCategoryIdsFromIndex(array $productIds)
225+
private function getCategoryIdsFromIndex(array $productIds): array
222226
{
223227
$categoryIds = [];
224228
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()
233234
);
235+
$categoryIds[] = $storeCategories;
234236
}
235-
$parentCategories = $categoryIds;
237+
$categoryIds = array_merge(...$categoryIds);
238+
239+
$parentCategories = [$categoryIds];
236240
foreach ($categoryIds as $categoryId) {
237241
$parentIds = explode('/', $this->getPathFromCategoryId($categoryId));
238-
$parentCategories = array_merge($parentCategories, $parentIds);
242+
$parentCategories[] = $parentIds;
239243
}
240-
$categoryIds = array_unique($parentCategories);
244+
$categoryIds = array_unique(array_merge(...$parentCategories));
241245

242246
return $categoryIds;
243247
}

0 commit comments

Comments
 (0)