Skip to content

Commit 9239bb3

Browse files
committed
Merge branch 'ACP2E-2928' of https://github.com/adobe-commerce-tier-4/magento2ce into T4-PR-03-18-2024
2 parents b2286ec + 899a0b4 commit 9239bb3

File tree

2 files changed

+90
-2
lines changed
  • app/code/Magento/Elasticsearch/SearchAdapter/Filter/Builder
  • dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogGraphQl

2 files changed

+90
-2
lines changed

app/code/Magento/Elasticsearch/SearchAdapter/Filter/Builder/Range.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ public function __construct(
2626
}
2727

2828
/**
29+
* Add the range filters
30+
*
2931
* @param RequestFilterInterface|RangeFilterRequest $filter
3032
* @return array
3133
*/
3234
public function buildFilter(RequestFilterInterface $filter)
3335
{
3436
$filterQuery = [];
3537
$fieldName = $this->fieldMapper->getFieldName($filter->getField());
36-
if ($filter->getFrom()) {
38+
if ($filter->getFrom() !== null) {
3739
$filterQuery['range'][$fieldName]['gte'] = $filter->getFrom();
3840
}
39-
if ($filter->getTo()) {
41+
if ($filter->getTo() !== null) {
4042
$filterQuery['range'][$fieldName]['lte'] = $filter->getTo();
4143
}
4244
return [$filterQuery];

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,90 @@ private function getProductSearchQueryWithMatchType(
371371
}
372372
QUERY;
373373
}
374+
375+
#[
376+
DataFixture(CategoryFixture::class, as: 'category'),
377+
DataFixture(
378+
ProductFixture::class,
379+
[
380+
'price' => 0,
381+
'category_ids' => ['$category.id$'],
382+
],
383+
'product1'
384+
),
385+
DataFixture(
386+
ProductFixture::class,
387+
[
388+
'price' => 0.5,
389+
'category_ids' => ['$category.id$'],
390+
],
391+
'product2'
392+
),
393+
DataFixture(
394+
ProductFixture::class,
395+
[
396+
'price' => 1,
397+
'category_ids' => ['$category.id$'],
398+
],
399+
'product3'
400+
),
401+
DataFixture(
402+
ProductFixture::class,
403+
[
404+
'price' => 1.5,
405+
'category_ids' => ['$category.id$'],
406+
],
407+
'product4'
408+
),
409+
]
410+
public function testProductSearchWithZeroPriceProducts()
411+
{
412+
413+
$response = $this->graphQlQuery($this->getSearchQueryBasedOnPriceRange(0, null));
414+
$this->assertEquals(4, $response['products']['totalResult']);
415+
416+
$response = $this->graphQlQuery($this->getSearchQueryBasedOnPriceRange(0, 0));
417+
$this->assertEquals(1, $response['products']['totalResult']);
418+
419+
$response = $this->graphQlQuery($this->getSearchQueryBasedOnPriceRange(0.5, null));
420+
$this->assertEquals(3, $response['products']['totalResult']);
421+
422+
$response = $this->graphQlQuery($this->getSearchQueryBasedOnPriceRange(0, 1));
423+
$this->assertEquals(3, $response['products']['totalResult']);
424+
}
425+
426+
/**
427+
* Prepare search query for products with price range
428+
*
429+
* @param float $priceFrom
430+
* @param float|null $priceTo
431+
* @return string
432+
*/
433+
private function getSearchQueryBasedOnPriceRange(float $priceFrom, null|float $priceTo): string
434+
{
435+
$priceToFilter = $priceTo !== null ? ',to:"' . $priceTo . '"' : '';
436+
return <<<QUERY
437+
query {
438+
products(
439+
pageSize: 10
440+
currentPage: 1,
441+
filter: {price:{from:"$priceFrom" $priceToFilter}}
442+
) {
443+
totalResult: total_count
444+
productItems: items {
445+
sku
446+
urlKey: url_key
447+
price: price_range {
448+
fullPrice: minimum_price {
449+
finalPrice: final_price {
450+
currency
451+
value
452+
}
453+
}
454+
}
455+
}
456+
}
457+
}
458+
QUERY;
459+
}
374460
}

0 commit comments

Comments
 (0)