Skip to content

Commit 9cab83d

Browse files
committed
ACP2E-316: Some product are missed from layered navigation with manually configured price ranges
1 parent 994da2d commit 9cab83d

File tree

6 files changed

+19
-100
lines changed

6 files changed

+19
-100
lines changed

app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class Price extends AbstractFilter
1919
{
2020
/** Price delta for filter */
21-
public const PRICE_DELTA = 0.001;
21+
public const PRICE_DELTA = 0.01;
2222

2323
/**
2424
* @var \Magento\Catalog\Model\Layer\Filter\DataProvider\Price
@@ -142,7 +142,7 @@ public function apply(\Magento\Framework\App\RequestInterface $request)
142142

143143
$this->getLayer()->getProductCollection()->addFieldToFilter(
144144
'price',
145-
['from' => $from, 'to' => empty($to) || $from == $to ? $to : $to - self::PRICE_DELTA]
145+
['from' => $from, 'to' => $to]
146146
);
147147

148148
$this->getLayer()->getState()->addFilter(
@@ -190,10 +190,6 @@ protected function _renderRangeLabel($fromPrice, $toPrice, $isLast = false)
190190
} elseif ($fromPrice == $toPrice && $this->dataProvider->getOnePriceIntervalValue()) {
191191
return $formattedFromPrice;
192192
} else {
193-
if ($fromPrice != $toPrice) {
194-
$toPrice -= .01;
195-
}
196-
197193
return __('%1 - %2', $formattedFromPrice, $this->priceCurrency->format($toPrice));
198194
}
199195
}
@@ -274,8 +270,8 @@ protected function getFrom($from)
274270
private function prepareData($key, $count, $isLast = false)
275271
{
276272
[$from, $to] = explode('_', $key);
277-
if ($isLast) {
278-
$to = '';
273+
if (!$isLast && !empty($to) && $to != $from) {
274+
$to -= self::PRICE_DELTA;
279275
}
280276
$label = $this->_renderRangeLabel($from, $to, $isLast);
281277
$value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();

app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Dynamic.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public function build(
4646
/** @var DynamicBucket $bucket */
4747
$algorithm = $this->algorithmRepository->get($bucket->getMethod(), ['dataProvider' => $dataProvider]);
4848
$data = $algorithm->getItems($bucket, $dimensions, $this->getEntityStorage($queryResult));
49-
return $this->prepareData($data);
49+
$stats = $queryResult['aggregations'][$bucket->getName()] ?? [];
50+
return $this->prepareData($data, $stats);
5051
}
5152

5253
/**
@@ -73,12 +74,16 @@ private function getEntityStorage(array $queryResult)
7374
* Prepare result data
7475
*
7576
* @param array $data
77+
* @param array $stats
7678
* @return array
7779
*/
78-
private function prepareData($data)
80+
private function prepareData(array $data, array $stats): array
7981
{
8082
$resultData = [];
81-
foreach ($data as $value) {
83+
foreach ($data as $key => $value) {
84+
if (!isset($data[$key+1]) && isset($stats['max'])) {
85+
$value['to'] = $stats['max'];
86+
}
8287
$rangeName = "{$value['from']}_{$value['to']}";
8388
$value['value'] = $rangeName;
8489
$resultData[$rangeName] = $value;

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

Lines changed: 7 additions & 2 deletions
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">$199.99</span>',
89+
'<span class="price">$100.00</span> - <span class="price">$200.00</span>',
9090
(string)$filters[0]->getLabel()
9191
);
9292
}
@@ -119,7 +119,12 @@ public function testGetSetCurrencyRate()
119119
* @magentoConfigFixture current_store catalog/layered_navigation/price_range_calculation manual
120120
* @magentoConfigFixture current_store catalog/layered_navigation/price_range_step 10
121121
* @magentoConfigFixture current_store catalog/layered_navigation/price_range_max_intervals 2
122-
* @magentoDataFixture Magento/CatalogSearch/_files/products_with_different_price.php
122+
* @magentoDataFixture Magento/Catalog/_files/categories_no_products.php
123+
* @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"category_ids":[4], "price":11}
124+
* @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"category_ids":[4], "price":13}
125+
* @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"category_ids":[4], "price":22}
126+
* @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"category_ids":[4], "price":22}
127+
* @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"category_ids":[4], "price":110}
123128
*/
124129
public function testGetItemsWithManualAlgorithm(): void
125130
{

dev/tests/integration/testsuite/Magento/CatalogSearch/_files/products_with_different_price.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/CatalogSearch/_files/products_with_different_price_rollback.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public function create()
6161
->create();
6262
}
6363
$this->data[SearchCriteria::SORT_ORDERS] = [$this->sortOrderBuilder->create()];
64-
$this->filters = [];
6564
return parent::create();
6665
}
6766

@@ -78,8 +77,6 @@ public function addFilter(\Magento\Framework\Api\Filter $filter)
7877
}
7978

8079
/**
81-
* Set sort order
82-
*
8380
* @param string $field
8481
* @param string $direction
8582
* @return $this

0 commit comments

Comments
 (0)