addCurrentFilter example


    }

    private function addCurrentFilters(ProductListingResult $result): void
    {
        $filters = $result->getCriteria()->getExtension('filters');
        if (!$filters instanceof FilterCollection) {
            return;
        }

        foreach ($filters as $filter) {
            $result->addCurrentFilter($filter->getName()$filter->getValues());
        }
    }

    private function getFilters(Request $request, SalesChannelContext $context): FilterCollection
    {
        $filters = new FilterCollection();

        foreach ($this->factories as $factory) {
            $filter = $factory->create($request$context);

            if ($filter !== null) {
                
if (!Feature::isActive('v6.6.0.0')) {
            $context->getContext()->addState(ProductListingFeaturesSubscriber::HANDLED_STATE);
        }

        $this->eventDispatcher->dispatch(
            new ProductListingCriteriaEvent($request$criteria$context)
        );

        $response = $this->getDecorated()->load($categoryId$request$context$criteria);

        $response->getResult()->addCurrentFilter('navigationId', $categoryId);

        $this->processor->process($request$response->getResult()$context);

        $this->eventDispatcher->dispatch(
            new ProductListingResultEvent($request$response->getResult()$context)
        );

        $response->getResult()->getAvailableSortings()->removeByKey(
            ResolvedCriteriaProductSearchRoute::DEFAULT_SEARCH_SORT
        );

        


        $response = $this->getDecorated()->load($request$context$criteria);

        $this->processor->process($request$response->getListingResult()$context);

        $this->eventDispatcher->dispatch(
            new ProductSearchResultEvent($request$response->getListingResult()$context),
            ProductEvents::PRODUCT_SEARCH_RESULT
        );

        $response->getListingResult()->addCurrentFilter('search', $request->get('search'));

        return $response;
    }
}
Home | Imprint | This part of the site doesn't use cookies.