Skip to content

Commit ccfa024

Browse files
MC-22739: Layered Navigation with different Scope for attribute
1 parent 06cb7ca commit ccfa024

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
require __DIR__ . '/../../Store/_files/second_website_with_two_stores.php';
1414

1515
$objectManager = Bootstrap::getObjectManager();
16-
/** @var ProductRepositoryInterface $productRepository */
17-
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
1816
/** @var WebsiteRepositoryInterface $websiteRepository */
1917
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
2018
$defaultWebsiteId = $websiteRepository->get('base')->getId();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77

88
require __DIR__ . '/category_with_different_price_products_rollback.php';
99
require __DIR__ . '/../../Store/_files/second_website_with_two_stores_rollback.php';
10-

dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/DecimalFilterTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,16 @@ protected function prepareFilterItems(AbstractFilter $filter): array
7474
/**
7575
* @inheritdoc
7676
*/
77-
protected function updateProducts(array $products, string $attributeCode): void
77+
protected function updateProducts(
78+
array $products,
79+
string $attributeCode,
80+
int $storeId = Store::DEFAULT_STORE_ID
81+
): void
7882
{
7983
$attribute = $this->attributeRepository->get($attributeCode);
8084

8185
foreach ($products as $productSku => $value) {
82-
$product = $this->productRepository->get($productSku, false, Store::DEFAULT_STORE_ID, true);
86+
$product = $this->productRepository->get($productSku, false, $storeId, true);
8387
$product->addData(
8488
[$attribute->getAttributeCode() => $value]
8589
);

dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/FilterScopeTest.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FilterScopeTest extends AbstractFiltersTest
4343
protected function setUp()
4444
{
4545
parent::setUp();
46-
$this->storeManager = $this->objectManager->create(StoreManagerInterface::class);
46+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
4747
$this->oldStoreId = (int)$this->storeManager->getStore()->getId();
4848
$this->currentStoreId = (int)$this->storeManager->getStore('fixture_second_store')->getId();
4949
}
@@ -67,15 +67,18 @@ public function testGetFilters(int $scope, array $products, array $expectation):
6767
);
6868
$this->updateProductsOnStore($products);
6969
$this->clearInstanceAndReindexSearch();
70-
$this->storeManager->setCurrentStore($this->currentStoreId);
71-
$this->navigationBlock->getLayer()->setCurrentCategory(
72-
$this->loadCategory('Category 999', $this->currentStoreId)
73-
);
74-
$this->navigationBlock->setLayout($this->layout);
75-
$filter = $this->getFilterByCode($this->navigationBlock->getFilters(), $this->getAttributeCode());
76-
$this->assertNotNull($filter);
77-
$this->assertEquals($expectation, $this->prepareFilterItems($filter));
78-
$this->storeManager->setCurrentStore($this->oldStoreId);
70+
try {
71+
$this->storeManager->setCurrentStore($this->currentStoreId);
72+
$this->navigationBlock->getLayer()->setCurrentCategory(
73+
$this->loadCategory('Category 999', $this->currentStoreId)
74+
);
75+
$this->navigationBlock->setLayout($this->layout);
76+
$filter = $this->getFilterByCode($this->navigationBlock->getFilters(), $this->getAttributeCode());
77+
$this->assertNotNull($filter);
78+
$this->assertEquals($expectation, $this->prepareFilterItems($filter));
79+
} finally {
80+
$this->storeManager->setCurrentStore($this->oldStoreId);
81+
}
7982
}
8083

8184
/**
@@ -144,11 +147,14 @@ protected function getAttributeCode(): string
144147
*/
145148
private function updateProductsOnStore(array $productsData): void
146149
{
147-
foreach ($productsData as $storeCode => $products) {
148-
$storeId = (int)$this->storeManager->getStore($storeCode)->getId();
149-
$this->storeManager->setCurrentStore($storeId);
150-
$this->updateProducts($products, $this->getAttributeCode(), $storeId);
150+
try {
151+
foreach ($productsData as $storeCode => $products) {
152+
$storeId = (int)$this->storeManager->getStore($storeCode)->getId();
153+
$this->storeManager->setCurrentStore($storeId);
154+
$this->updateProducts($products, $this->getAttributeCode(), $storeId);
155+
}
156+
} finally {
157+
$this->storeManager->setCurrentStore($this->oldStoreId);
151158
}
152-
$this->storeManager->setCurrentStore($this->oldStoreId);
153159
}
154160
}

0 commit comments

Comments
 (0)