Skip to content

Commit 3786d5a

Browse files
authored
ENGCOM-7707: 28628 price range wildcards #28745
2 parents 46450bf + 6f647d1 commit 3786d5a

File tree

11 files changed

+47
-56
lines changed

11 files changed

+47
-56
lines changed

app/code/Magento/Catalog/Model/Layer/Filter/Price/Render.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function renderRangeLabel($fromPrice, $toPrice)
7272
}
7373

7474
/**
75+
* Prepare range data
76+
*
7577
* @param int $range
7678
* @param int[] $dbRanges
7779
* @return array
@@ -81,12 +83,10 @@ public function renderRangeData($range, $dbRanges)
8183
if (empty($dbRanges)) {
8284
return [];
8385
}
84-
$lastIndex = array_keys($dbRanges);
85-
$lastIndex = $lastIndex[count($lastIndex) - 1];
8686

8787
foreach ($dbRanges as $index => $count) {
88-
$fromPrice = $index == 1 ? '' : ($index - 1) * $range;
89-
$toPrice = $index == $lastIndex ? '' : $index * $range;
88+
$fromPrice = $index == 1 ? 0 : ($index - 1) * $range;
89+
$toPrice = $index * $range;
9090
$this->itemDataBuilder->addItemData(
9191
$this->renderRangeLabel($fromPrice, $toPrice),
9292
$fromPrice . '-' . $toPrice,

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,16 @@ public function getCurrencyRate()
176176
*
177177
* @param float|string $fromPrice
178178
* @param float|string $toPrice
179+
* @param boolean $isLast
179180
* @return float|\Magento\Framework\Phrase
180181
*/
181-
protected function _renderRangeLabel($fromPrice, $toPrice)
182+
protected function _renderRangeLabel($fromPrice, $toPrice, $isLast = false)
182183
{
183184
$fromPrice = empty($fromPrice) ? 0 : $fromPrice * $this->getCurrencyRate();
184185
$toPrice = empty($toPrice) ? $toPrice : $toPrice * $this->getCurrencyRate();
185186

186187
$formattedFromPrice = $this->priceCurrency->format($fromPrice);
187-
if ($toPrice === '') {
188+
if ($isLast) {
188189
return __('%1 and above', $formattedFromPrice);
189190
} elseif ($fromPrice == $toPrice && $this->dataProvider->getOnePriceIntervalValue()) {
190191
return $formattedFromPrice;
@@ -215,12 +216,15 @@ protected function _getItemsData()
215216

216217
$data = [];
217218
if (count($facets) > 1) { // two range minimum
219+
$lastFacet = array_key_last($facets);
218220
foreach ($facets as $key => $aggregation) {
219221
$count = $aggregation['count'];
220222
if (strpos($key, '_') === false) {
221223
continue;
222224
}
223-
$data[] = $this->prepareData($key, $count, $data);
225+
226+
$isLast = $lastFacet === $key;
227+
$data[] = $this->prepareData($key, $count, $isLast);
224228
}
225229
}
226230

@@ -264,18 +268,13 @@ protected function getFrom($from)
264268
*
265269
* @param string $key
266270
* @param int $count
271+
* @param boolean $isLast
267272
* @return array
268273
*/
269-
private function prepareData($key, $count)
274+
private function prepareData($key, $count, $isLast = false)
270275
{
271-
list($from, $to) = explode('_', $key);
272-
if ($from == '*') {
273-
$from = $this->getFrom($to);
274-
}
275-
if ($to == '*') {
276-
$to = $this->getTo($to);
277-
}
278-
$label = $this->_renderRangeLabel($from, $to);
276+
[$from, $to] = explode('_', $key);
277+
$label = $this->_renderRangeLabel($from, $to, $isLast);
279278
$value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();
280279

281280
$data = [

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(Repository $algorithmRepository, EntityStorageFactor
3535
}
3636

3737
/**
38-
* {@inheritdoc}
38+
* @inheritdoc
3939
*/
4040
public function build(
4141
RequestBucketInterface $bucket,
@@ -46,9 +46,7 @@ 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-
$resultData = $this->prepareData($data);
50-
51-
return $resultData;
49+
return $this->prepareData($data);
5250
}
5351

5452
/**
@@ -77,12 +75,9 @@ private function prepareData($data)
7775
{
7876
$resultData = [];
7977
foreach ($data as $value) {
80-
$from = is_numeric($value['from']) ? $value['from'] : '*';
81-
$to = is_numeric($value['to']) ? $value['to'] : '*';
82-
unset($value['from'], $value['to']);
83-
84-
$rangeName = "{$from}_{$to}";
85-
$resultData[$rangeName] = array_merge(['value' => $rangeName], $value);
78+
$rangeName = "{$value['from']}_{$value['to']}";
79+
$value['value'] = $rangeName;
80+
$resultData[$rangeName] = $value;
8681
}
8782

8883
return $resultData;

app/code/Magento/Elasticsearch/SearchAdapter/Dynamic/DataProvider.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,9 @@ public function prepareData($range, array $dbRanges)
235235
{
236236
$data = [];
237237
if (!empty($dbRanges)) {
238-
$lastIndex = array_keys($dbRanges);
239-
$lastIndex = $lastIndex[count($lastIndex) - 1];
240238
foreach ($dbRanges as $index => $count) {
241-
$fromPrice = $index == 1 ? '' : ($index - 1) * $range;
242-
$toPrice = $index == $lastIndex ? '' : $index * $range;
239+
$fromPrice = $index == 1 ? 0 : ($index - 1) * $range;
240+
$toPrice = $index * $range;
243241
$data[] = [
244242
'from' => $fromPrice,
245243
'to' => $toPrice,

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Dynamic/DataProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,13 @@ public function testPrepareData()
390390
{
391391
$expectedResult = [
392392
[
393-
'from' => '',
393+
'from' => 0,
394394
'to' => 10,
395395
'count' => 1,
396396
],
397397
[
398398
'from' => 10,
399-
'to' => '',
399+
'to' => 20,
400400
'count' => 1,
401401
],
402402
];

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ public function testSearchAndFilterByCustomAttribute()
570570
],
571571
[
572572
'count' => 1,
573-
'label' => '40-*',
574-
'value' => '40_*',
573+
'label' => '40-50',
574+
'value' => '40_50',
575575

576576
],
577577
],
@@ -1431,8 +1431,8 @@ public function testFilterProductsForExactMatchingName()
14311431
'count' => 1,
14321432
],
14331433
[
1434-
'label' => '20-*',
1435-
'value' => '20_*',
1434+
'label' => '20-30',
1435+
'value' => '20_30',
14361436
'count' => 1,
14371437
]
14381438
]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testGetFilters(): void
5353
['is_filterable' => '1'],
5454
[
5555
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
56-
['label' => '$20.00 and above', 'value' => '20-', 'count' => 1],
56+
['label' => '$20.00 and above', 'value' => '20-30', 'count' => 1],
5757
],
5858
'Category 1'
5959
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getFiltersDataProvider(): array
7676
],
7777
[
7878
'label' => '<span class="price">$60.00</span> and above',
79-
'value' => '60-',
79+
'value' => '60-70',
8080
'count' => 1,
8181
],
8282
],
@@ -94,7 +94,7 @@ public function getFiltersDataProvider(): array
9494
],
9595
[
9696
'label' => '<span class="price">$50.00</span> and above',
97-
'value' => '50-',
97+
'value' => '50-60',
9898
'count' => 1,
9999
],
100100
],

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ public function getFiltersDataProvider(): array
7171
'expectation' => [
7272
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
7373
['label' => '$20.00 - $29.99', 'value' => '20-30', 'count' => 1],
74-
['label' => '$50.00 and above', 'value' => '50-', 'count' => 1],
74+
['label' => '$50.00 and above', 'value' => '50-60', 'count' => 1],
7575
],
7676
],
7777
'auto_calculation_variation_with_big_price_difference' => [
7878
'config' => ['catalog/layered_navigation/price_range_calculation' => 'auto'],
7979
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 300.00],
8080
'expectation' => [
81-
['label' => '$0.00 - $99.99', 'value' => '-100', 'count' => 2],
82-
['label' => '$300.00 and above', 'value' => '300-', 'count' => 1],
81+
['label' => '$0.00 - $99.99', 'value' => '0-100', 'count' => 2],
82+
['label' => '$300.00 and above', 'value' => '300-400', 'count' => 1],
8383
],
8484
],
8585
'auto_calculation_variation_with_fixed_price_step' => [
@@ -88,7 +88,7 @@ public function getFiltersDataProvider(): array
8888
'expectation' => [
8989
['label' => '$300.00 - $399.99', 'value' => '300-400', 'count' => 1],
9090
['label' => '$400.00 - $499.99', 'value' => '400-500', 'count' => 1],
91-
['label' => '$500.00 and above', 'value' => '500-', 'count' => 1],
91+
['label' => '$500.00 and above', 'value' => '500-600', 'count' => 1],
9292
],
9393
],
9494
'improved_calculation_variation_with_small_price_difference' => [
@@ -98,8 +98,8 @@ public function getFiltersDataProvider(): array
9898
],
9999
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 50.00],
100100
'expectation' => [
101-
['label' => '$0.00 - $49.99', 'value' => '-50', 'count' => 2],
102-
['label' => '$50.00 and above', 'value' => '50-', 'count' => 1],
101+
['label' => '$0.00 - $19.99', 'value' => '0-20', 'count' => 1],
102+
['label' => '$20.00 and above', 'value' => '20-50', 'count' => 2],
103103
],
104104
],
105105
'improved_calculation_variation_with_big_price_difference' => [
@@ -109,8 +109,8 @@ public function getFiltersDataProvider(): array
109109
],
110110
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 300.00],
111111
'expectation' => [
112-
['label' => '$0.00 - $299.99', 'value' => '-300', 'count' => 2.0],
113-
['label' => '$300.00 and above', 'value' => '300-', 'count' => 1.0],
112+
['label' => '$0.00 - $19.99', 'value' => '0-20', 'count' => 1],
113+
['label' => '$20.00 and above', 'value' => '20-300', 'count' => 2],
114114
],
115115
],
116116
'manual_calculation_with_price_step_200' => [
@@ -121,7 +121,7 @@ public function getFiltersDataProvider(): array
121121
'products_data' => ['simple1000' => 300.00, 'simple1001' => 300.00, 'simple1002' => 500.00],
122122
'expectation' => [
123123
['label' => '$200.00 - $399.99', 'value' => '200-400', 'count' => 2],
124-
['label' => '$400.00 and above', 'value' => '400-', 'count' => 1],
124+
['label' => '$400.00 and above', 'value' => '400-600', 'count' => 1],
125125
],
126126
],
127127
'manual_calculation_with_price_step_10' => [
@@ -132,7 +132,7 @@ public function getFiltersDataProvider(): array
132132
'products_data' => ['simple1000' => 300.00, 'simple1001' => 300.00, 'simple1002' => 500.00],
133133
'expectation' => [
134134
['label' => '$300.00 - $309.99', 'value' => '300-310', 'count' => 2],
135-
['label' => '$500.00 and above', 'value' => '500-', 'count' => 1],
135+
['label' => '$500.00 and above', 'value' => '500-510', 'count' => 1],
136136
],
137137
],
138138
'manual_calculation_with_number_of_intervals_10' => [
@@ -145,7 +145,7 @@ public function getFiltersDataProvider(): array
145145
'expectation' => [
146146
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
147147
['label' => '$20.00 - $29.99', 'value' => '20-30', 'count' => 1],
148-
['label' => '$30.00 and above', 'value' => '30-', 'count' => 1],
148+
['label' => '$30.00 and above', 'value' => '30-40', 'count' => 1],
149149
],
150150
],
151151
'manual_calculation_with_number_of_intervals_2' => [
@@ -157,7 +157,7 @@ public function getFiltersDataProvider(): array
157157
'products_data' => ['simple1000' => 10.00, 'simple1001' => 20.00, 'simple1002' => 30.00],
158158
'expectation' => [
159159
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
160-
['label' => '$20.00 and above', 'value' => '20-', 'count' => 2],
160+
['label' => '$20.00 and above', 'value' => '20-30', 'count' => 2],
161161
],
162162
],
163163
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testGetFilters(): void
3232
['is_filterable_in_search' => 1],
3333
[
3434
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => 1],
35-
['label' => '$20.00 and above', 'value' => '20-', 'count' => 1],
35+
['label' => '$20.00 and above', 'value' => '20-30', 'count' => 1],
3636
]
3737
);
3838
}

0 commit comments

Comments
 (0)