Skip to content

Commit d876fcf

Browse files
[Filter] Update to Live Component
1 parent 433cc0e commit d876fcf

14 files changed

Lines changed: 275 additions & 306 deletions

File tree

src/Controller/Shop/FilterController.php

Lines changed: 0 additions & 119 deletions
This file was deleted.

src/Form/Type/Filter/GallyDynamicFilterType.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@
2929
use Symfony\Component\Form\Extension\Core\Type\RangeType;
3030
use Symfony\Component\Form\FormBuilderInterface;
3131
use Symfony\Component\HttpFoundation\RequestStack;
32-
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
3332

3433
class GallyDynamicFilterType extends AbstractType
3534
{
3635
/**
3736
* @param TaxonRepository<TaxonInterface> $taxonRepository
3837
*/
3938
public function __construct(
40-
private UrlGeneratorInterface $router,
4139
private RequestStack $requestStack,
4240
private TaxonRepository $taxonRepository,
4341
private LocaleContextInterface $localeContext,
@@ -53,6 +51,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5351
{
5452
$isTaxonPage = $this->isTaxonPage();
5553
$categoryFieldAdded = false;
54+
$facetContext = $this->buildFacetContext();
5655

5756
if ($isTaxonPage && !$this->hasCategoryAggregation()) {
5857
// Gally doesn't always return a "category" aggregation on taxon listing pages (e.g. a
@@ -118,7 +117,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
118117
'choices' => $choices,
119118
'expanded' => true,
120119
'multiple' => true,
121-
'search_url' => $this->buildSearchUrl($aggregation->getField()),
120+
'facet_search' => $facetContext['search'],
121+
'facet_filters' => $facetContext['filters'],
122+
'facet_taxon_code' => $facetContext['taxonCode'],
122123
'has_more' => $aggregation->hasMore(),
123124
]
124125
);
@@ -225,7 +226,10 @@ private function getCurrentCategoryId(): ?string
225226
return \is_string($categoryId) && '' !== $categoryId ? $categoryId : null;
226227
}
227228

228-
private function buildSearchUrl(string $field): string
229+
/**
230+
* @return array{search: ?string, filters: array<string, mixed>, taxonCode: ?string}
231+
*/
232+
private function buildFacetContext(): array
229233
{
230234
$request = $this->requestStack->getCurrentRequest();
231235
/** @var array<string, mixed> $queryParameters */
@@ -234,20 +238,18 @@ private function buildSearchUrl(string $field): string
234238
/** @var array<string, array<string, mixed>> $criteria */
235239
$criteria = $parameters->get('criteria', []);
236240
$query = $parameters->get('query', null);
237-
$search = (\is_string($query) && '' !== $query) ? $query : ((isset($criteria['search'], $criteria['search']['value'])) ? $criteria['search']['value'] : '');
238-
unset($criteria['search']);
241+
$search = (\is_string($query) && '' !== $query) ? $query : ((isset($criteria['search'], $criteria['search']['value']) && \is_string($criteria['search']['value'])) ? $criteria['search']['value'] : null);
239242
/** @var string $slug */
240243
$slug = $request?->attributes->get('slug') ?? '';
241244
$taxon = $this->taxonRepository->findOneBySlug($slug, $this->localeContext->getLocaleCode());
242245

243-
return $this->router->generate(
244-
'gally_filter_view_more_ajax',
245-
[
246-
'filterField' => $field,
247-
'search' => $search,
248-
'filters' => $criteria,
249-
'taxon' => $taxon?->getId(),
250-
]
251-
);
246+
/** @var array<string, mixed> $filters */
247+
$filters = \is_array($criteria['gally'] ?? null) ? $criteria['gally'] : [];
248+
249+
return [
250+
'search' => $search,
251+
'filters' => $filters,
252+
'taxonCode' => $taxon?->getCode(),
253+
];
252254
}
253255
}

src/Grid/Filter/Type/SelectFilterType.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ final class SelectFilterType extends AbstractType
2424
{
2525
public function configureOptions(OptionsResolver $resolver): void
2626
{
27-
$resolver->setDefined(['has_more', 'search_url'])
27+
$resolver->setDefined(['has_more', 'facet_search', 'facet_filters', 'facet_taxon_code'])
2828
->addAllowedTypes('has_more', 'bool')
29-
->addAllowedTypes('search_url', 'string');
29+
->addAllowedTypes('facet_search', ['string', 'null'])
30+
->addAllowedTypes('facet_filters', 'array')
31+
->addAllowedTypes('facet_taxon_code', ['string', 'null']);
3032
}
3133

3234
public function getParent(): string
@@ -39,6 +41,10 @@ public function buildView(FormView $view, FormInterface $form, array $options):
3941
// @phpstan-ignore offsetAccess.nonOffsetAccessible
4042
$view->vars['has_more'] = \array_key_exists('has_more', $options) ? $options['has_more'] : false;
4143
// @phpstan-ignore offsetAccess.nonOffsetAccessible
42-
$view->vars['search_url'] = \array_key_exists('search_url', $options) ? $options['search_url'] : null;
44+
$view->vars['facet_search'] = \array_key_exists('facet_search', $options) ? $options['facet_search'] : null;
45+
// @phpstan-ignore offsetAccess.nonOffsetAccessible
46+
$view->vars['facet_filters'] = \array_key_exists('facet_filters', $options) ? $options['facet_filters'] : [];
47+
// @phpstan-ignore offsetAccess.nonOffsetAccessible
48+
$view->vars['facet_taxon_code'] = \array_key_exists('facet_taxon_code', $options) ? $options['facet_taxon_code'] : null;
4349
}
4450
}

src/Resources/assets/shop/controllers/FacetOptionsController.js

Lines changed: 0 additions & 124 deletions
This file was deleted.

src/Resources/config/services.xml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<import resource="services/search.xml"/>
99
<import resource="services/twig.xml"/>
1010
<import resource="services/twig/component/product.xml"/>
11+
<import resource="services/twig/component/filter.xml"/>
1112
<import resource="services/tracking.xml"/>
1213
</imports>
1314

@@ -39,20 +40,6 @@
3940
<tag name="controller.service_arguments" />
4041
</service>
4142

42-
<service id="Gally\SyliusPlugin\Controller\Shop\FilterController">
43-
<argument type="service" id="Gally\SyliusPlugin\Indexer\Provider\CatalogProvider" />
44-
<argument type="service" id="Gally\Sdk\Service\SearchManager" />
45-
<argument type="service" id="sylius.context.channel" />
46-
<argument type="service" id="sylius.context.locale" />
47-
<argument type="service" id="sylius.repository.taxon" />
48-
<argument type="service" id="form.factory" />
49-
<argument type="service" id="Gally\SyliusPlugin\Search\FilterConverter" />
50-
<call method="setContainer">
51-
<argument type="service" id="service_container" />
52-
</call>
53-
<tag name="controller.service_arguments" />
54-
</service>
55-
5643
<service id="Gally\SyliusPlugin\Controller\Shop\SearchController">
5744
<argument type="service" id="Gally\SyliusPlugin\Search\Finder" />
5845
<argument type="service" id="sylius.context.channel" />

src/Resources/config/services/search.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
</service>
5151

5252
<service id="Gally\SyliusPlugin\Form\Type\Filter\GallyDynamicFilterType" autoconfigure="true">
53-
<argument type="service" id="router" />
5453
<argument type="service" id="request_stack" />
5554
<argument type="service" id="sylius.repository.taxon" />
5655
<argument type="service" id="sylius.context.locale" />

0 commit comments

Comments
 (0)