Skip to content

Commit b4767d6

Browse files
committed
#31252:default store breadcrumbs returned for products which in both root categories - fixed requested changes
1 parent e30e7af commit b4767d6

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,36 @@ protected function reindex()
172172
{
173173
foreach ($this->storeManager->getStores() as $store) {
174174
if ($this->getPathFromCategoryId($store->getRootCategoryId())) {
175-
$this->currentStore = $store;
175+
$this->setCurrentStore($store);
176176
$this->reindexRootCategory($store);
177177
$this->reindexAnchorCategories($store);
178178
$this->reindexNonAnchorCategories($store);
179179
}
180180
}
181181
}
182182

183+
/**
184+
* Set current store
185+
*
186+
* @param StoreInterface $store
187+
* @return $this
188+
*/
189+
private function setCurrentStore(StoreInterface $store): self
190+
{
191+
$this->currentStore = $store;
192+
return $this;
193+
}
194+
195+
/**
196+
* Get current store
197+
*
198+
* @return StoreInterface
199+
*/
200+
private function getCurrentStore(): StoreInterface
201+
{
202+
return $this->currentStore;
203+
}
204+
183205
/**
184206
* Return validated table name
185207
*
@@ -485,6 +507,7 @@ protected function hasAnchorSelect(Store $store)
485507
*/
486508
protected function createAnchorSelect(Store $store)
487509
{
510+
$this->setCurrentStore($store);
488511
$isAnchorAttributeId = $this->config->getAttribute(
489512
\Magento\Catalog\Model\Category::ENTITY,
490513
'is_anchor'
@@ -494,7 +517,6 @@ protected function createAnchorSelect(Store $store)
494517
$rootCatIds = explode('/', $this->getPathFromCategoryId($store->getRootCategoryId()));
495518
array_pop($rootCatIds);
496519

497-
$this->currentStore = $store;
498520
$temporaryTreeTable = $this->makeTempCategoryTreeIndex();
499521

500522
$productMetadata = $this->metadataPool->getMetadata(ProductInterface::class);
@@ -692,7 +714,7 @@ protected function fillTempCategoryTreeIndex($temporaryName)
692714
['ccacs' => $this->getTable('catalog_category_entity_int')],
693715
'ccacs.' . $categoryLinkField . ' = c.' . $categoryLinkField
694716
. ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' .
695-
$this->currentStore->getId(),
717+
$this->getCurrentStore()->getId(),
696718
[]
697719
)->where(
698720
$this->connection->getIfNullSql('ccacs.value', 'ccacd.value') . ' = ?',
@@ -708,7 +730,7 @@ protected function fillTempCategoryTreeIndex($temporaryName)
708730
foreach ($categories as $category) {
709731
$categoriesTree = explode('/', $category['path']);
710732
foreach ($categoriesTree as $parentId) {
711-
if (!in_array($this->currentStore->getRootCategoryId(), $categoriesTree, true)) {
733+
if (!in_array($this->getCurrentStore()->getRootCategoryId(), $categoriesTree, true)) {
712734
break;
713735
}
714736

dev/tests/integration/testsuite/Magento/Catalog/_files/product_in_two_root_categories_rollback.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,7 @@
66

77
declare(strict_types=1);
88

9-
use Magento\Catalog\Api\CategoryRepositoryInterface;
10-
use Magento\Catalog\Model\ResourceModel\Category\Collection;
11-
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
12-
use Magento\TestFramework\Helper\Bootstrap;
139
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
1410

15-
//$objectManager = Bootstrap::getObjectManager();
16-
17-
//$categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
18-
//$categoryCollectionFactory = $objectManager->get(CollectionFactory::class);
19-
20-
///** @var $categoryCollection Collection */
21-
//$categoryCollection = $categoryCollectionFactory->create();
22-
//$categoryCollection->addFieldToFilter('name', ['eq' => 'Second Root Category']);
23-
//$secondRootCategory = $categoryCollection->getFirstItem();
24-
//$categoryRepository->delete($secondRootCategory);
25-
2611
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/store_with_second_root_category_rollback.php');
2712
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_with_category_rollback.php');

0 commit comments

Comments
 (0)