Skip to content

Commit 94422cb

Browse files
committed
Always use linkIds for category flat EAV indexing.
This keeps full and rows indexing consistent.
1 parent ed52dc9 commit 94422cb

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Flat/AbstractAction.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,14 @@ protected function getAttributeValues($entityIds, $storeId)
376376

377377
$attributes = $this->getAttributes();
378378
$attributesType = ['varchar', 'int', 'decimal', 'text', 'datetime'];
379+
$linkField = $this->getCategoryMetadata()->getLinkField();
379380
foreach ($attributesType as $type) {
380381
foreach ($this->getAttributeTypeValues($type, $entityIds, $storeId) as $row) {
381-
if (isset($row[$this->getCategoryMetadata()->getLinkField()]) && isset($row['attribute_id'])) {
382+
if (isset($row[$linkField]) && isset($row['attribute_id'])) {
382383
$attributeId = $row['attribute_id'];
383384
if (isset($attributes[$attributeId])) {
384385
$attributeCode = $attributes[$attributeId]['attribute_code'];
385-
$values[$row[$this->getCategoryMetadata()->getLinkField()]][$attributeCode] = $row['value'];
386+
$values[$row[$linkField]][$attributeCode] = $row['value'];
386387
}
387388
}
388389
}

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Full.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,22 @@ protected function populateFlatTables(array $stores)
6464
}
6565
/** @TODO Do something with chunks */
6666
$categoriesIdsChunks = array_chunk($categoriesIds[$store->getRootCategoryId()], 500);
67+
6768
foreach ($categoriesIdsChunks as $categoriesIdsChunk) {
6869
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
70+
$linkField = $this->categoryMetadata->getLinkField();
71+
6972
$data = [];
7073
foreach ($categories[$store->getRootCategoryId()] as $category) {
71-
if (!isset($attributesData[$category[$this->categoryMetadata->getLinkField()]])) {
74+
if (!isset($attributesData[$category[$linkField]])) {
7275
continue;
7376
}
7477
$category['store_id'] = $store->getId();
7578
$data[] = $this->prepareValuesToInsert(
76-
array_merge($category, $attributesData[$category[$this->categoryMetadata->getLinkField()]])
79+
array_merge($category, $attributesData[$category[$linkField]])
7780
);
7881
}
82+
7983
$this->connection->insertMultiple(
8084
$this->addTemporaryTableSuffix($this->getMainStoreTable($store->getId())),
8185
$data

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,24 @@ public function reindex(array $entityIds = [], $useTempTable = false)
6969
$categoriesIdsChunk = $this->filterIdsByStore($categoriesIdsChunk, $store);
7070

7171
$attributesData = $this->getAttributeValues($categoriesIdsChunk, $store->getId());
72+
$linkField = $this->categoryMetadata->getLinkField();
7273
$data = [];
7374
foreach ($categoriesIdsChunk as $categoryId) {
74-
if (!isset($attributesData[$categoryId])) {
75-
continue;
76-
}
77-
7875
try {
7976
$category = $this->categoryRepository->get($categoryId);
8077
} catch (NoSuchEntityException $e) {
8178
continue;
8279
}
8380

81+
$categoryData = $category->getData();
82+
if (!isset($attributesData[$categoryData[$linkField]])) {
83+
continue;
84+
}
85+
8486
$data[] = $this->prepareValuesToInsert(
8587
array_merge(
86-
$category->getData(),
87-
$attributesData[$categoryId],
88+
$categoryData,
89+
$attributesData[$categoryData[$linkField]],
8890
['store_id' => $store->getId()]
8991
)
9092
);

0 commit comments

Comments
 (0)