Skip to content

Commit 1b8cd08

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

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ abstract class AbstractAction
123123
*/
124124
private $queryGenerator;
125125

126+
/**
127+
* @var int
128+
*/
129+
private $currentStoreId = 0;
130+
126131
/**
127132
* @param ResourceConnection $resource
128133
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -164,6 +169,7 @@ protected function reindex()
164169
{
165170
foreach ($this->storeManager->getStores() as $store) {
166171
if ($this->getPathFromCategoryId($store->getRootCategoryId())) {
172+
$this->currentStoreId = $store->getId();
167173
$this->reindexRootCategory($store);
168174
$this->reindexAnchorCategories($store);
169175
$this->reindexNonAnchorCategories($store);
@@ -499,7 +505,7 @@ protected function createAnchorSelect(Store $store)
499505
'cc2.parent_id = cc.entity_id AND cc.entity_id NOT IN (' . implode(
500506
',',
501507
$rootCatIds
502-
) . ') AND cc2.store_id = ' . $store->getId(),
508+
) . ')',
503509
[]
504510
)->joinInner(
505511
['ccp' => $this->getTable('catalog_category_product')],
@@ -631,12 +637,6 @@ protected function makeTempCategoryTreeIndex()
631637
null,
632638
['nullable' => false, 'unsigned' => true]
633639
);
634-
$temporaryTable->addColumn(
635-
'store_id',
636-
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
637-
null,
638-
['nullable' => false, 'unsigned' => true]
639-
);
640640
// Each entry will be unique.
641641
$temporaryTable->addIndex(
642642
'idx_primary',
@@ -649,12 +649,6 @@ protected function makeTempCategoryTreeIndex()
649649
['child_id'],
650650
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
651651
);
652-
653-
$temporaryTable->addIndex(
654-
'store_id',
655-
['store_id'],
656-
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
657-
);
658652
// Drop the temporary table in case it already exists on this (persistent?) connection.
659653
$this->connection->dropTemporaryTable($temporaryName);
660654
$this->connection->createTemporaryTable($temporaryTable);
@@ -684,11 +678,19 @@ protected function fillTempCategoryTreeIndex($temporaryName)
684678
['c' => $this->getTable('catalog_category_entity')],
685679
['entity_id', 'path']
686680
)->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']
681+
['ccacd' => $this->getTable('catalog_category_entity_int')],
682+
'ccacd.' . $categoryLinkField . ' = c.' . $categoryLinkField . ' AND ccacd.store_id = 0' .
683+
' AND ccacd.attribute_id = ' . $isActiveAttributeId,
684+
[]
685+
)->joinLeft(
686+
['ccacs' => $this->getTable('catalog_category_entity_int')],
687+
'ccacs.' . $categoryLinkField . ' = c.' . $categoryLinkField
688+
. ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' .
689+
$this->currentStoreId,
690+
[]
691+
)->where(
692+
$this->connection->getIfNullSql('ccacs.value', 'ccacd.value') . ' = ?',
693+
1
692694
),
693695
'entity_id'
694696
);
@@ -699,13 +701,13 @@ protected function fillTempCategoryTreeIndex($temporaryName)
699701
foreach ($this->connection->fetchAll($select) as $category) {
700702
foreach (explode('/', $category['path']) as $parentId) {
701703
if ($parentId !== $category['entity_id']) {
702-
$values[] = [$parentId, $category['entity_id'], $category['store_id']];
704+
$values[] = [$parentId, $category['entity_id']];
703705
}
704706
}
705707
}
706708

707709
if (count($values) > 0) {
708-
$this->connection->insertArray($temporaryName, ['parent_id', 'child_id', 'store_id'], $values);
710+
$this->connection->insertArray($temporaryName, ['parent_id', 'child_id'], $values);
709711
}
710712
}
711713
}

0 commit comments

Comments
 (0)