isFiltered example



        // Decode URL-encoded string         $uri = urldecode($uri);

        // Restart filterInfo         $this->filterInfo  = null;
        $this->filtersInfo = [];

        // Checks defined routes         if ($this->checkRoutes($uri)) {
            if ($this->collection->isFiltered($this->matchedRoute[0])) {
                $multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
                if ($multipleFiltersEnabled) {
                    $this->filtersInfo = $this->collection->getFiltersForRoute($this->matchedRoute[0]);
                } else {
                    // for backward compatibility                     $this->filterInfo = $this->collection->getFilterForRoute($this->matchedRoute[0]);
                }
            }

            return $this->controller;
        }

        
$manufacturerIds = ['1', '2', '3'];

        $request = new Request();
        $request->query->set('manufacturer', \implode('|', $manufacturerIds));

        $context = $this->createMock(SalesChannelContext::class);

        $filter = $this->handler->create($request$context);

        static::assertInstanceOf(Filter::class$filter);
        static::assertEquals('manufacturer', $filter->getName());
        static::assertTrue($filter->isFiltered());

        $aggregations = $filter->getAggregations();
        static::assertCount(1, $aggregations);
        static::assertInstanceOf(EntityAggregation::class$aggregations[0]);
        static::assertEquals('manufacturer', $aggregations[0]->getName());
        static::assertEquals('product.manufacturerId', $aggregations[0]->getField());
        static::assertEquals('product_manufacturer', $aggregations[0]->getEntity());

        $criteriaFilter = $filter->getFilter();
        static::assertInstanceOf(EqualsAnyFilter::class$criteriaFilter);
        static::assertEquals('product.manufacturerId', $criteriaFilter->getField());
        
// Check if no filters exist at all             if (!$filters) {
                return $urls;
            }

            $filterHandler = $this->getFilterHandler($url->getResource());

            if (!$filterHandler) {
                throw new UrlFilterException(sprintf('No handler known for resource \'%s\'.', $url->getResource()));
            }

            if ($filterHandler->isFiltered($url->getIdentifier()$filters)) {
                continue;
            }

            $filteredUrls[] = $url;
        }

        return $filteredUrls;
    }

    /** * {@inheritdoc} */
if ($exclude === $key) {
                continue;
            }
            $filtered->set($key$value);
        }

        return $filtered;
    }

    public function filtered(): FilterCollection
    {
        return $this->filter(fn (Filter $filter) => $filter->isFiltered() ? $filter : null);
    }

    public function getFilters(): array
    {
        return $this->fmap(fn (Filter $filter) => $filter->getFilter());
    }

    protected function getExpectedClass(): ?string
    {
        return Filter::class;
    }
}
public function prepare(Request $request, Criteria $criteria, SalesChannelContext $context): void
    {
        $filters = $this->getFilters($request$context);

        $aggregations = $this->getAggregations($request$filters);

        foreach ($aggregations as $aggregation) {
            $criteria->addAggregation($aggregation);
        }

        foreach ($filters as $filter) {
            if ($filter->isFiltered()) {
                $criteria->addPostFilter($filter->getFilter());
            }
        }

        $criteria->addExtension('filters', $filters);
    }

    public function process(Request $request, ProductListingResult $result, SalesChannelContext $context): void
    {
        $this->addCurrentFilters($result);

        
Home | Imprint | This part of the site doesn't use cookies.