diff --git a/app/code/Magento/Catalog/Model/Layer/Filter/Price/Render.php b/app/code/Magento/Catalog/Model/Layer/Filter/Price/Render.php
index 77dedb9eb0121..3494fd00a8b6c 100644
--- a/app/code/Magento/Catalog/Model/Layer/Filter/Price/Render.php
+++ b/app/code/Magento/Catalog/Model/Layer/Filter/Price/Render.php
@@ -72,6 +72,8 @@ public function renderRangeLabel($fromPrice, $toPrice)
}
/**
+ * Prepare range data
+ *
* @param int $range
* @param int[] $dbRanges
* @return array
@@ -81,12 +83,10 @@ public function renderRangeData($range, $dbRanges)
if (empty($dbRanges)) {
return [];
}
- $lastIndex = array_keys($dbRanges);
- $lastIndex = $lastIndex[count($lastIndex) - 1];
foreach ($dbRanges as $index => $count) {
- $fromPrice = $index == 1 ? '' : ($index - 1) * $range;
- $toPrice = $index == $lastIndex ? '' : $index * $range;
+ $fromPrice = $index == 1 ? 0 : ($index - 1) * $range;
+ $toPrice = $index * $range;
$this->itemDataBuilder->addItemData(
$this->renderRangeLabel($fromPrice, $toPrice),
$fromPrice . '-' . $toPrice,
diff --git a/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php b/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php
index 332bb991bf29f..b2aaa054ebc34 100644
--- a/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php
+++ b/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php
@@ -176,15 +176,16 @@ public function getCurrencyRate()
*
* @param float|string $fromPrice
* @param float|string $toPrice
+ * @param boolean $isLast
* @return float|\Magento\Framework\Phrase
*/
- protected function _renderRangeLabel($fromPrice, $toPrice)
+ protected function _renderRangeLabel($fromPrice, $toPrice, $isLast = false)
{
$fromPrice = empty($fromPrice) ? 0 : $fromPrice * $this->getCurrencyRate();
$toPrice = empty($toPrice) ? $toPrice : $toPrice * $this->getCurrencyRate();
$formattedFromPrice = $this->priceCurrency->format($fromPrice);
- if ($toPrice === '') {
+ if ($isLast) {
return __('%1 and above', $formattedFromPrice);
} elseif ($fromPrice == $toPrice && $this->dataProvider->getOnePriceIntervalValue()) {
return $formattedFromPrice;
@@ -215,12 +216,15 @@ protected function _getItemsData()
$data = [];
if (count($facets) > 1) { // two range minimum
+ $lastFacet = array_key_last($facets);
foreach ($facets as $key => $aggregation) {
$count = $aggregation['count'];
if (strpos($key, '_') === false) {
continue;
}
- $data[] = $this->prepareData($key, $count, $data);
+
+ $isLast = $lastFacet === $key;
+ $data[] = $this->prepareData($key, $count, $isLast);
}
}
@@ -264,18 +268,13 @@ protected function getFrom($from)
*
* @param string $key
* @param int $count
+ * @param boolean $isLast
* @return array
*/
- private function prepareData($key, $count)
+ private function prepareData($key, $count, $isLast = false)
{
- list($from, $to) = explode('_', $key);
- if ($from == '*') {
- $from = $this->getFrom($to);
- }
- if ($to == '*') {
- $to = $this->getTo($to);
- }
- $label = $this->_renderRangeLabel($from, $to);
+ [$from, $to] = explode('_', $key);
+ $label = $this->_renderRangeLabel($from, $to, $isLast);
$value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();
$data = [
diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Dynamic.php b/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Dynamic.php
index 1e106023ea00d..548a57e55f3e2 100644
--- a/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Dynamic.php
+++ b/app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Dynamic.php
@@ -35,7 +35,7 @@ public function __construct(Repository $algorithmRepository, EntityStorageFactor
}
/**
- * {@inheritdoc}
+ * @inheritdoc
*/
public function build(
RequestBucketInterface $bucket,
@@ -46,9 +46,7 @@ public function build(
/** @var DynamicBucket $bucket */
$algorithm = $this->algorithmRepository->get($bucket->getMethod(), ['dataProvider' => $dataProvider]);
$data = $algorithm->getItems($bucket, $dimensions, $this->getEntityStorage($queryResult));
- $resultData = $this->prepareData($data);
-
- return $resultData;
+ return $this->prepareData($data);
}
/**
@@ -77,12 +75,9 @@ private function prepareData($data)
{
$resultData = [];
foreach ($data as $value) {
- $from = is_numeric($value['from']) ? $value['from'] : '*';
- $to = is_numeric($value['to']) ? $value['to'] : '*';
- unset($value['from'], $value['to']);
-
- $rangeName = "{$from}_{$to}";
- $resultData[$rangeName] = array_merge(['value' => $rangeName], $value);
+ $rangeName = "{$value['from']}_{$value['to']}";
+ $value['value'] = $rangeName;
+ $resultData[$rangeName] = $value;
}
return $resultData;
diff --git a/app/code/Magento/Elasticsearch/SearchAdapter/Dynamic/DataProvider.php b/app/code/Magento/Elasticsearch/SearchAdapter/Dynamic/DataProvider.php
index 496a77e4c5ac3..7bc64b59ffe78 100644
--- a/app/code/Magento/Elasticsearch/SearchAdapter/Dynamic/DataProvider.php
+++ b/app/code/Magento/Elasticsearch/SearchAdapter/Dynamic/DataProvider.php
@@ -235,11 +235,9 @@ public function prepareData($range, array $dbRanges)
{
$data = [];
if (!empty($dbRanges)) {
- $lastIndex = array_keys($dbRanges);
- $lastIndex = $lastIndex[count($lastIndex) - 1];
foreach ($dbRanges as $index => $count) {
- $fromPrice = $index == 1 ? '' : ($index - 1) * $range;
- $toPrice = $index == $lastIndex ? '' : $index * $range;
+ $fromPrice = $index == 1 ? 0 : ($index - 1) * $range;
+ $toPrice = $index * $range;
$data[] = [
'from' => $fromPrice,
'to' => $toPrice,
diff --git a/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Dynamic/DataProviderTest.php b/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Dynamic/DataProviderTest.php
index c5b9089acd91c..0595b667f4ee8 100644
--- a/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Dynamic/DataProviderTest.php
+++ b/app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Dynamic/DataProviderTest.php
@@ -390,13 +390,13 @@ public function testPrepareData()
{
$expectedResult = [
[
- 'from' => '',
+ 'from' => 0,
'to' => 10,
'count' => 1,
],
[
'from' => 10,
- 'to' => '',
+ 'to' => 20,
'count' => 1,
],
];
diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php
index 1a95a3d6f4925..dd5b5827c8017 100644
--- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php
@@ -570,8 +570,8 @@ public function testSearchAndFilterByCustomAttribute()
],
[
'count' => 1,
- 'label' => '40-*',
- 'value' => '40_*',
+ 'label' => '40-50',
+ 'value' => '40_50',
],
],
@@ -1431,8 +1431,8 @@ public function testFilterProductsForExactMatchingName()
'count' => 1,
],
[
- 'label' => '20-*',
- 'value' => '20_*',
+ 'label' => '20-30',
+ 'value' => '20_30',
'count' => 1,
]
]
diff --git a/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/Bundle/PriceFilterTest.php b/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/Bundle/PriceFilterTest.php
index dd4fdde250c03..b6508e3b3dfda 100644
--- a/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/Bundle/PriceFilterTest.php
+++ b/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/Bundle/PriceFilterTest.php
@@ -53,7 +53,7 @@ public function testGetFilters(): void
['is_filterable' => '1'],
[
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
- ['label' => '$20.00 and above', 'value' => '20-', 'count' => 1],
+ ['label' => '$20.00 and above', 'value' => '20-30', 'count' => 1],
],
'Category 1'
);
diff --git a/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/Configurable/PriceFilterTest.php b/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/Configurable/PriceFilterTest.php
index 07882b68d62d5..e226881b9cfcc 100644
--- a/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/Configurable/PriceFilterTest.php
+++ b/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/Configurable/PriceFilterTest.php
@@ -76,7 +76,7 @@ public function getFiltersDataProvider(): array
],
[
'label' => '$60.00 and above',
- 'value' => '60-',
+ 'value' => '60-70',
'count' => 1,
],
],
@@ -94,7 +94,7 @@ public function getFiltersDataProvider(): array
],
[
'label' => '$50.00 and above',
- 'value' => '50-',
+ 'value' => '50-60',
'count' => 1,
],
],
diff --git a/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/PriceFilterTest.php b/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/PriceFilterTest.php
index 3b2673b18635a..97928463620f4 100644
--- a/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/PriceFilterTest.php
+++ b/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Category/PriceFilterTest.php
@@ -71,15 +71,15 @@ public function getFiltersDataProvider(): array
'expectation' => [
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
['label' => '$20.00 - $29.99', 'value' => '20-30', 'count' => 1],
- ['label' => '$50.00 and above', 'value' => '50-', 'count' => 1],
+ ['label' => '$50.00 and above', 'value' => '50-60', 'count' => 1],
],
],
'auto_calculation_variation_with_big_price_difference' => [
'config' => ['catalog/layered_navigation/price_range_calculation' => 'auto'],
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 300.00],
'expectation' => [
- ['label' => '$0.00 - $99.99', 'value' => '-100', 'count' => 2],
- ['label' => '$300.00 and above', 'value' => '300-', 'count' => 1],
+ ['label' => '$0.00 - $99.99', 'value' => '0-100', 'count' => 2],
+ ['label' => '$300.00 and above', 'value' => '300-400', 'count' => 1],
],
],
'auto_calculation_variation_with_fixed_price_step' => [
@@ -88,7 +88,7 @@ public function getFiltersDataProvider(): array
'expectation' => [
['label' => '$300.00 - $399.99', 'value' => '300-400', 'count' => 1],
['label' => '$400.00 - $499.99', 'value' => '400-500', 'count' => 1],
- ['label' => '$500.00 and above', 'value' => '500-', 'count' => 1],
+ ['label' => '$500.00 and above', 'value' => '500-600', 'count' => 1],
],
],
'improved_calculation_variation_with_small_price_difference' => [
@@ -98,8 +98,8 @@ public function getFiltersDataProvider(): array
],
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 50.00],
'expectation' => [
- ['label' => '$0.00 - $49.99', 'value' => '-50', 'count' => 2],
- ['label' => '$50.00 and above', 'value' => '50-', 'count' => 1],
+ ['label' => '$0.00 - $19.99', 'value' => '0-20', 'count' => 1],
+ ['label' => '$20.00 and above', 'value' => '20-50', 'count' => 2],
],
],
'improved_calculation_variation_with_big_price_difference' => [
@@ -109,8 +109,8 @@ public function getFiltersDataProvider(): array
],
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 300.00],
'expectation' => [
- ['label' => '$0.00 - $299.99', 'value' => '-300', 'count' => 2.0],
- ['label' => '$300.00 and above', 'value' => '300-', 'count' => 1.0],
+ ['label' => '$0.00 - $19.99', 'value' => '0-20', 'count' => 1],
+ ['label' => '$20.00 and above', 'value' => '20-300', 'count' => 2],
],
],
'manual_calculation_with_price_step_200' => [
@@ -121,7 +121,7 @@ public function getFiltersDataProvider(): array
'products_data' => ['simple1000' => 300.00, 'simple1001' => 300.00, 'simple1002' => 500.00],
'expectation' => [
['label' => '$200.00 - $399.99', 'value' => '200-400', 'count' => 2],
- ['label' => '$400.00 and above', 'value' => '400-', 'count' => 1],
+ ['label' => '$400.00 and above', 'value' => '400-600', 'count' => 1],
],
],
'manual_calculation_with_price_step_10' => [
@@ -132,7 +132,7 @@ public function getFiltersDataProvider(): array
'products_data' => ['simple1000' => 300.00, 'simple1001' => 300.00, 'simple1002' => 500.00],
'expectation' => [
['label' => '$300.00 - $309.99', 'value' => '300-310', 'count' => 2],
- ['label' => '$500.00 and above', 'value' => '500-', 'count' => 1],
+ ['label' => '$500.00 and above', 'value' => '500-510', 'count' => 1],
],
],
'manual_calculation_with_number_of_intervals_10' => [
@@ -145,7 +145,7 @@ public function getFiltersDataProvider(): array
'expectation' => [
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
['label' => '$20.00 - $29.99', 'value' => '20-30', 'count' => 1],
- ['label' => '$30.00 and above', 'value' => '30-', 'count' => 1],
+ ['label' => '$30.00 and above', 'value' => '30-40', 'count' => 1],
],
],
'manual_calculation_with_number_of_intervals_2' => [
@@ -157,7 +157,7 @@ public function getFiltersDataProvider(): array
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 30.00],
'expectation' => [
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
- ['label' => '$20.00 and above', 'value' => '20-', 'count' => 2],
+ ['label' => '$20.00 and above', 'value' => '20-30', 'count' => 2],
],
],
];
diff --git a/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Search/Bundle/PriceFilterTest.php b/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Search/Bundle/PriceFilterTest.php
index 435dd29e16dfa..760f4031b8844 100644
--- a/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Search/Bundle/PriceFilterTest.php
+++ b/dev/tests/integration/testsuite/Magento/LayeredNavigation/Block/Navigation/Search/Bundle/PriceFilterTest.php
@@ -32,7 +32,7 @@ public function testGetFilters(): void
['is_filterable_in_search' => 1],
[
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
- ['label' => '$20.00 and above', 'value' => '20-', 'count' => 1],
+ ['label' => '$20.00 and above', 'value' => '20-30', 'count' => 1],
]
);
}
diff --git a/lib/internal/Magento/Framework/Search/Dynamic/Algorithm/Improved.php b/lib/internal/Magento/Framework/Search/Dynamic/Algorithm/Improved.php
index a3e9ed61824ed..c4f6c67200b2b 100644
--- a/lib/internal/Magento/Framework/Search/Dynamic/Algorithm/Improved.php
+++ b/lib/internal/Magento/Framework/Search/Dynamic/Algorithm/Improved.php
@@ -44,7 +44,7 @@ public function __construct(
}
/**
- * {@inheritdoc}
+ * @inheritdoc
*/
public function getItems(
BucketInterface $bucket,
@@ -64,13 +64,12 @@ public function getItems(
$aggregations['count']
);
- $this->algorithm->setLimits($aggregations['min'], $aggregations['max'] + 0.01);
+ $this->algorithm->setLimits($aggregations['min'], $aggregations['max']);
$interval = $this->dataProvider->getInterval($bucket, $dimensions, $entityStorage);
$data = $this->algorithm->calculateSeparators($interval);
- $data[0]['from'] = ''; // We should not calculate min and max value
- $data[count($data) - 1]['to'] = '';
+ $data[0]['from'] = 0;
$dataSize = count($data);
for ($key = 0; $key < $dataSize; $key++) {