Skip to content

Commit 9fc5818

Browse files
committed
ACP2E-316: Some product are missed from layered navigation with manually configured price ranges
1 parent 52808c9 commit 9fc5818

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Layer/Filter/PriceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testApplyWithCustomCurrencyRate()
8686
$filters = $this->model->getLayer()->getState()->getFilters();
8787
$this->assertArrayHasKey(0, $filters);
8888
$this->assertEquals(
89-
'<span class="price">$100.00</span> - <span class="price">$200.00</span>',
89+
'<span class="price">$100.00</span> - <span class="price">$199.99</span>',
9090
(string)$filters[0]->getLabel()
9191
);
9292
}

dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/AbstractFiltersTest.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,20 @@ protected function getCategoryFiltersAndAssert(
121121

122122
if ($attributeData['is_filterable']) {
123123
$this->assertNotNull($filter);
124-
$this->assertEquals($expectation, $this->prepareFilterItems($filter));
124+
$preparedItems = $this->prepareFilterItems($filter);
125+
$this->assertCount(count($expectation), $preparedItems);
126+
127+
foreach ($preparedItems as $key => $preparedItem) {
128+
$this->assertEquals($expectation[$key], $preparedItem);
129+
$item = $filter->getItems()[$key];
130+
$this->createNavigationBlockInstance();
131+
$this->navigationBlock->getRequest()->setParams($this->getRequestParams($item->getValueString()));
132+
$this->navigationBlock->getLayer()->setCurrentCategory($category);
133+
$this->navigationBlock->setLayout($this->layout);
134+
$collectionSize = $this->navigationBlock->getLayer()->getProductCollection()->count();
135+
$this->assertEquals($expectation[$key]['count'], $collectionSize);
136+
$this->assertEquals($collectionSize, $item->getData('count'));
137+
}
125138
} else {
126139
$this->assertNull($filter);
127140
}
@@ -351,19 +364,22 @@ protected function loadCategory(string $categoryName, int $storeId): CategoryInt
351364
*/
352365
protected function createNavigationBlockInstance(): void
353366
{
354-
$layerResolver = $this->objectManager->create(Resolver::class);
355-
356367
if ($this->getLayerType() === Resolver::CATALOG_LAYER_SEARCH) {
357-
$layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);
358-
$this->navigationBlock = $this->objectManager->create(
359-
SearchNavigationBlock::class,
360-
[
361-
'layerResolver' => $layerResolver,
362-
]
363-
);
368+
$class = SearchNavigationBlock::class;
369+
$this->objectManager->removeSharedInstance('searchFilterList');
364370
} else {
365-
$this->navigationBlock = $this->objectManager->create(CategoryNavigationBlock::class);
371+
$class = CategoryNavigationBlock::class;
372+
$this->objectManager->removeSharedInstance('categoryFilterList');
366373
}
374+
375+
$layerResolver = $this->objectManager->create(Resolver::class);
376+
$layerResolver->create($this->getLayerType());
377+
$this->navigationBlock = $this->objectManager->create(
378+
$class,
379+
[
380+
'layerResolver' => $layerResolver,
381+
]
382+
);
367383
}
368384

369385
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function getFiltersDataProvider(): array
9898
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 50.00],
9999
'expectation' => [
100100
['label' => '$0.00 - $19.99', 'value' => '0-20', 'count' => 1],
101-
['label' => '$20.00 and above', 'value' => '20-50', 'count' => 2],
101+
['label' => '$20.00 and above', 'value' => '20-50.01', 'count' => 2],
102102
],
103103
],
104104
'improved_calculation_variation_with_big_price_difference' => [
@@ -109,7 +109,7 @@ public function getFiltersDataProvider(): array
109109
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 300.00],
110110
'expectation' => [
111111
['label' => '$0.00 - $19.99', 'value' => '0-20', 'count' => 1],
112-
['label' => '$20.00 and above', 'value' => '20-300', 'count' => 2],
112+
['label' => '$20.00 and above', 'value' => '20-300.01', 'count' => 2],
113113
],
114114
],
115115
'manual_calculation_with_price_step_200' => [
@@ -156,7 +156,7 @@ public function getFiltersDataProvider(): array
156156
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 30.00],
157157
'expectation' => [
158158
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
159-
['label' => '$20.00 and above', 'value' => '20-30', 'count' => 2],
159+
['label' => '$20.00 and above', 'value' => '20-30.01', 'count' => 2],
160160
],
161161
],
162162
];

lib/internal/Magento/Framework/Search/Dynamic/Algorithm/Improved.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public function getItems(
7575
for ($key = 0; $key < $dataSize; $key++) {
7676
if (isset($data[$key + 1])) {
7777
$data[$key]['to'] = $data[$key + 1]['from'];
78+
} else {
79+
$data[$key]['to'] = max($data[$key]['to'], $aggregations['max'] + 0.01);
7880
}
7981
}
8082

0 commit comments

Comments
 (0)