Open MartijnHarte opened 6 years ago
@MartijnHarte Could you give a db dump or some extended info so I can properly replicate the issue on my side and adjust? I think I may understand what is happening, but i'm not 100% sure. I guess this is related to when there are more than a single option for a product, so there are various combinations, like Color and Size of a t-shirt, if you select a color, you can't filter by size anymore, am I right?
The extended multi_dynamic_aggregate_options is there for a reason, because it has additional functionality that is lacking in the ONGR base and is needed for Sylius, so it can't be just dropped.
@psihius
Here are the steps to reproduce:
```php */ final class DefaultController extends Controller { /** * @var ViewHandlerInterface */ private $viewHandler; /** * @var ProductListViewFactoryInterface */ private $productListViewFactory; /** * @var FilterManagerInterface */ private $filterManager; /** * @param ViewHandlerInterface $viewHandler * @param ProductListViewFactoryInterface $productListViewFactory * @param FilterManagerInterface $filterManager */ public function __construct( ViewHandlerInterface $viewHandler, ProductListViewFactoryInterface $productListViewFactory, FilterManagerInterface $filterManager ) { $this->viewHandler = $viewHandler; $this->productListViewFactory = $productListViewFactory; $this->filterManager = $filterManager; } /** * @param Request $request * * @return Response * @throws \InvalidArgumentException */ public function __invoke(Request $request) { $response = $this->filterManager->handleRequest($request); /** @var \Sylius\ElasticSearchPlugin\Controller\ProductListView $data */ $data = $this->productListViewFactory->createFromSearchResponse( $response ); $view = View::create($data, Response::HTTP_OK); $view->setTemplate($request->attributes->get('template')); $view->setTemplateVar('results'); return $this->viewHandler->handle($view); } } ```
```yaml product_index: path: /{_locale}/c/{slug} methods: [GET] defaults: _controller: 'AppBundle\Controller\DefaultController' template: "@AppBundle/list.html.twig" requirements: slug: .+ ```
```yaml services: AppBundle\Controller\DefaultController: arguments: - '@fos_rest.view_handler' - '@sylius_elastic_search.factory.product_list_view' - '@ongr_filter_manager.manager.search_list' - '@sylius.context.channel' ```
```twig {% extends '@SyliusShop/layout.html.twig' %} {% block content %}
/en_US/c/t-shirts?channel=US_WEB&enabled=1&taxonSlug=t-shirts
Changing the following configuration solves the problem:
options:
type: sylius_elastic_search.multi_dynamic_aggregate_options
request_field: options
document_field: variants>variants.options>variants.options.value.raw
options:
name_field: variants.options.name.raw
sort_type: _term
sort_order: asc
size: 100
options:
type: sylius_elastic_search.multi_dynamic_aggregate
request_field: options
document_field: variants.options>variants.options.value.raw
options:
name_field: variants.options.name.raw
sort_type: _term
sort_order: asc
size: 100
When selecting an option in a filter using the default configuration makes other option groups disappear.
The default configuration of options is:
The document field variants>variants.options>variants.options.value.raw defines a double nested aggregation to get to the variant's options. Because of this double nested aggregation the sylius_elastic_search.multi_dynamic_aggregate_options filter type is needed to override ONGR's default functionality. This override however, breaks the default functionality.
Changing the document field to variants.options>variants.options.value.raw (directly pointed to the variant's options in a single nested aggregation) makes the need for an overridden filter type redundant. By changing this document field, we're able to make use of the sylius_elastic_search.multi_dynamic_aggregate filter type. The excess OptionMultiDynamicAggregate could be removed.
By making use of the MultiDynamicAggregate filter type, functionality of multiple option groups is restored.
The new configuration for options would be: