ProductListingCriteriaEvent example

    public function load(string $categoryId, Request $request, SalesChannelContext $context, Criteria $criteria): ProductListingRouteResponse
    {
        $criteria->addState(self::STATE);

        $this->processor->prepare($request$criteria$context);

        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)
        );

        
$this->salesChannel = $salesChannel;
    }

    /** * @dataProvider manufacturerProvider * * @param list<string> $expected */
    public function testManufacturerFilter(array $expected, Request $request): void
    {
        $criteria = new Criteria();
        $event = new ProductListingCriteriaEvent($request$criteria, Generator::createSalesChannelContext());
        $this->eventDispatcher->dispatch($event);

        if (empty($expected)) {
            static::assertCount(0, $criteria->getPostFilters());

            return;
        }

        static::assertCount(1, $criteria->getPostFilters());
        $filter = $criteria->getPostFilters()[0];

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