From 49e532e65ae2bb94c573771a0f88e7b5dad467d6 Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Tue, 17 Sep 2024 12:21:19 +0200 Subject: [PATCH 1/2] Put taxons after products in search in test app --- dist/src/Resources/config/search/taxons.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/src/Resources/config/search/taxons.yaml b/dist/src/Resources/config/search/taxons.yaml index 39a93c9..5602a4e 100644 --- a/dist/src/Resources/config/search/taxons.yaml +++ b/dist/src/Resources/config/search/taxons.yaml @@ -16,7 +16,7 @@ monsieurbiz_sylius_search: instant: '@MonsieurBizSyliusSearchPlugin/Instant/Taxon/_box.html.twig' #mapping_provider: '...' # by default MonsieurBiz\SyliusSearchPlugin\Mapping\YamlWithLocaleProvider datasource: 'App\Search\Model\Datasource\TaxonDatasource' # by default MonsieurBiz\SyliusSearchPlugin\Model\Datasource\RepositoryDatasource - position: -1 + position: 2 automapper_classes: sources: taxon: '%sylius.model.taxon.class%' From cf4167942c39f5f66f7fa32c602353bdcbe1d263 Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Tue, 17 Sep 2024 12:22:33 +0200 Subject: [PATCH 2/2] Clean range field values for price if needed --- src/Search/Request/RequestConfiguration.php | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Search/Request/RequestConfiguration.php b/src/Search/Request/RequestConfiguration.php index 5622cf5..526c9a0 100644 --- a/src/Search/Request/RequestConfiguration.php +++ b/src/Search/Request/RequestConfiguration.php @@ -67,6 +67,8 @@ public function getAppliedFilters(string $type = null): array return \is_array($query) ? array_filter($query) : $query; }, $requestQuery); + $this->manageRangeField('price'); + return null !== $type ? ($requestQuery[$type] ?? []) : $requestQuery; } @@ -82,6 +84,41 @@ public function getPage(): int return (int) $this->request->get('page', 1); } + /** + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ + public function manageRangeField(string $field): void + { + $range = $this->request->get($field, []); + if (!\is_array($range) || empty($range)) { + return; + } + + /** @var array $range */ + + // Reverse min and max if min is greater than max + if (isset($range['min'], $range['max'])) { + $min = (float) $range['min']; + $max = (float) $range['max']; + if ($min > $max) { + $range['min'] = $range['max']; + $range['max'] = $range['min']; + } + } + + // Remove min value is 0 or less + if (isset($range['min']) && 0 >= (float) $range['min']) { + unset($range['min']); + } + + // Remove max value if it is 0 or less + if (isset($range['max']) && 0 >= (float) $range['max']) { + unset($range['max']); + } + + $this->request->query->set($field, $range); + } + public function getLimit(): int { /** @phpstan-ignore-next-line */