Skip to content

Commit

Permalink
Fix issue with search filtering on empty price field value
Browse files Browse the repository at this point in the history
  • Loading branch information
senghe committed Aug 8, 2024
1 parent aa6798d commit 3a4ea02
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/Form/Type/SearchFacetsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Webmozart\Assert\Assert;

final class SearchFacetsType extends AbstractType
{
Expand Down
2 changes: 1 addition & 1 deletion src/PropertyBuilder/ProductCreatedAtPropertyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

namespace BitBag\SyliusElasticsearchPlugin\PropertyBuilder;

use Webmozart\Assert\Assert;
use Elastica\Document;
use FOS\ElasticaBundle\Event\PostTransformEvent;
use Sylius\Component\Core\Model\ProductInterface;
use Webmozart\Assert\Assert;

final class ProductCreatedAtPropertyBuilder extends AbstractBuilder
{
Expand Down
9 changes: 7 additions & 2 deletions src/QueryBuilder/HasPriceBetweenQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ public function buildQuery(array $data): ?AbstractQuery
$dataMinPrice = $this->getDataByKey($data, $this->priceNameResolver->resolveMinPriceName());
$dataMaxPrice = $this->getDataByKey($data, $this->priceNameResolver->resolveMaxPriceName());

$minPrice = (null !== $dataMinPrice) ? $this->resolveBasePrice($dataMinPrice) : null;
$maxPrice = (null !== $dataMaxPrice) ? $this->resolveBasePrice($dataMaxPrice) : null;
// PHPStan is not right here: Only booleans are allowed in a ternary operator condition, string|null given
// When we change the functionality, it breaks search filtering on empty price fields value
/** @phpstan-ignore-next-line */
$minPrice = $dataMinPrice ? $this->resolveBasePrice($dataMinPrice) : null;

/** @phpstan-ignore-next-line */
$maxPrice = $dataMaxPrice ? $this->resolveBasePrice($dataMaxPrice) : null;

/** @var string $channelCode */
$channelCode = $this->channelContext->getChannel()->getCode();
Expand Down
2 changes: 1 addition & 1 deletion src/QueryBuilder/ProductOptionsByTaxonQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;

use Webmozart\Assert\Assert;
use Elastica\Query\AbstractQuery;
use Elastica\Query\BoolQuery;
use Webmozart\Assert\Assert;

final class ProductOptionsByTaxonQueryBuilder implements QueryBuilderInterface
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Application/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en_US
bitbag_es_shop_price_facet_interval: 1000000
bitbag_es_shop_price_facet_interval: 1000

services:
bitbag_sylius_elasticsearch_plugin.facet.registry:
Expand Down

0 comments on commit 3a4ea02

Please sign in to comment.