Skip to content

Commit 68933c1

Browse files
committed
MAGETWO-70303: [GITHUB] Anchor categories are showing products of disabled subcategories #9002
- Change index table and temporary table
1 parent 8fd89cf commit 68933c1

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ protected function createAnchorSelect(Store $store)
499499
'cc2.parent_id = cc.entity_id AND cc.entity_id NOT IN (' . implode(
500500
',',
501501
$rootCatIds
502-
) . ')',
502+
) . ') AND cc2.store_id = ' . $store->getId(),
503503
[]
504504
)->joinInner(
505505
['ccp' => $this->getTable('catalog_category_product')],
@@ -586,6 +586,8 @@ protected function createAnchorSelect(Store $store)
586586
}
587587

588588
/**
589+
* Get temporary table name
590+
*
589591
* Get temporary table name for concurrent indexing in persistent connection
590592
* Temp table name is NOT shared between action instances and each action has it's own temp tree index
591593
*
@@ -629,6 +631,12 @@ protected function makeTempCategoryTreeIndex()
629631
null,
630632
['nullable' => false, 'unsigned' => true]
631633
);
634+
$temporaryTable->addColumn(
635+
'store_id',
636+
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
637+
null,
638+
['nullable' => false, 'unsigned' => true]
639+
);
632640
// Each entry will be unique.
633641
$temporaryTable->addIndex(
634642
'idx_primary',
@@ -642,6 +650,11 @@ protected function makeTempCategoryTreeIndex()
642650
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
643651
);
644652

653+
$temporaryTable->addIndex(
654+
'store_id',
655+
['store_id'],
656+
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
657+
);
645658
// Drop the temporary table in case it already exists on this (persistent?) connection.
646659
$this->connection->dropTemporaryTable($temporaryName);
647660
$this->connection->createTemporaryTable($temporaryTable);
@@ -659,11 +672,23 @@ protected function makeTempCategoryTreeIndex()
659672
*/
660673
protected function fillTempCategoryTreeIndex($temporaryName)
661674
{
675+
$isActiveAttributeId = $this->config->getAttribute(
676+
\Magento\Catalog\Model\Category::ENTITY,
677+
'is_active'
678+
)->getId();
679+
$categoryMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\CategoryInterface::class);
680+
$categoryLinkField = $categoryMetadata->getLinkField();
662681
$selects = $this->prepareSelectsByRange(
663682
$this->connection->select()
664683
->from(
665684
['c' => $this->getTable('catalog_category_entity')],
666685
['entity_id', 'path']
686+
)->joinInner(
687+
['ccei' => $this->getTable('catalog_category_entity_int')],
688+
'ccei.' . $categoryLinkField . ' = c.' . $categoryLinkField .
689+
' AND ccei.attribute_id = ' . $isActiveAttributeId .
690+
' AND ccei.value = 1',
691+
['store_id']
667692
),
668693
'entity_id'
669694
);
@@ -674,13 +699,13 @@ protected function fillTempCategoryTreeIndex($temporaryName)
674699
foreach ($this->connection->fetchAll($select) as $category) {
675700
foreach (explode('/', $category['path']) as $parentId) {
676701
if ($parentId !== $category['entity_id']) {
677-
$values[] = [$parentId, $category['entity_id']];
702+
$values[] = [$parentId, $category['entity_id'], $category['store_id']];
678703
}
679704
}
680705
}
681706

682707
if (count($values) > 0) {
683-
$this->connection->insertArray($temporaryName, ['parent_id', 'child_id'], $values);
708+
$this->connection->insertArray($temporaryName, ['parent_id', 'child_id', 'store_id'], $values);
684709
}
685710
}
686711
}

0 commit comments

Comments
 (0)