@@ -371,4 +371,90 @@ private function getProductSearchQueryWithMatchType(
371
371
}
372
372
QUERY ;
373
373
}
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
+ }
374
460
}
0 commit comments