Skip to content

Commit f39a5d9

Browse files
committed
Default store (Root category A) breadcrumbs are being returned for New Store (Root category B) when Product belongs to both root categories - fixed catalog_category_product index
1 parent 1e846a4 commit f39a5d9

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\DB\Query\Generator as QueryGenerator;
1414
use Magento\Framework\DB\Select;
1515
use Magento\Framework\EntityManager\MetadataPool;
16+
use Magento\Store\Api\Data\StoreInterface;
1617
use Magento\Store\Model\Store;
1718

1819
// phpcs:disable Magento2.Classes.AbstractApi
@@ -126,9 +127,9 @@ abstract class AbstractAction
126127
private $queryGenerator;
127128

128129
/**
129-
* @var int
130+
* @var StoreInterface
130131
*/
131-
private $currentStoreId = 0;
132+
private $currentStore;
132133

133134
/**
134135
* @param ResourceConnection $resource
@@ -171,7 +172,7 @@ protected function reindex()
171172
{
172173
foreach ($this->storeManager->getStores() as $store) {
173174
if ($this->getPathFromCategoryId($store->getRootCategoryId())) {
174-
$this->currentStoreId = $store->getId();
175+
$this->currentStore = $store;
175176
$this->reindexRootCategory($store);
176177
$this->reindexAnchorCategories($store);
177178
$this->reindexNonAnchorCategories($store);
@@ -379,13 +380,13 @@ private function addFilteringByChildProductsToSelect(Select $select, Store $stor
379380
[]
380381
)->joinLeft(
381382
['child_cpsd' => $this->getTable('catalog_product_entity_int')],
382-
'child_cpsd.' . $linkField . ' = '. 'relation_product_entity.' . $linkField
383+
'child_cpsd.' . $linkField . ' = ' . 'relation_product_entity.' . $linkField
383384
. ' AND child_cpsd.store_id = 0'
384385
. ' AND child_cpsd.attribute_id = ' . $statusAttributeId,
385386
[]
386387
)->joinLeft(
387388
['child_cpss' => $this->getTable('catalog_product_entity_int')],
388-
'child_cpss.' . $linkField . ' = '. 'relation_product_entity.' . $linkField . ''
389+
'child_cpss.' . $linkField . ' = ' . 'relation_product_entity.' . $linkField . ''
389390
. ' AND child_cpss.attribute_id = child_cpsd.attribute_id'
390391
. ' AND child_cpss.store_id = ' . $store->getId(),
391392
[]
@@ -493,6 +494,7 @@ protected function createAnchorSelect(Store $store)
493494
$rootCatIds = explode('/', $this->getPathFromCategoryId($store->getRootCategoryId()));
494495
array_pop($rootCatIds);
495496

497+
$this->currentStore = $store;
496498
$temporaryTreeTable = $this->makeTempCategoryTreeIndex();
497499

498500
$productMetadata = $this->metadataPool->getMetadata(ProductInterface::class);
@@ -690,7 +692,7 @@ protected function fillTempCategoryTreeIndex($temporaryName)
690692
['ccacs' => $this->getTable('catalog_category_entity_int')],
691693
'ccacs.' . $categoryLinkField . ' = c.' . $categoryLinkField
692694
. ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' .
693-
$this->currentStoreId,
695+
$this->currentStore->getId(),
694696
[]
695697
)->where(
696698
$this->connection->getIfNullSql('ccacs.value', 'ccacd.value') . ' = ?',
@@ -702,8 +704,14 @@ protected function fillTempCategoryTreeIndex($temporaryName)
702704
foreach ($selects as $select) {
703705
$values = [];
704706

705-
foreach ($this->connection->fetchAll($select) as $category) {
706-
foreach (explode('/', $category['path']) as $parentId) {
707+
$categories = $this->connection->fetchAll($select);
708+
foreach ($categories as $category) {
709+
$categoriesTree = explode('/', $category['path']);
710+
foreach ($categoriesTree as $parentId) {
711+
if (!in_array($this->currentStore->getRootCategoryId(), $categoriesTree, true)) {
712+
break;
713+
}
714+
707715
if ($parentId !== $category['entity_id']) {
708716
$values[] = [$parentId, $category['entity_id']];
709717
}

0 commit comments

Comments
 (0)