ProductSearchCriteriaEvent example

$criteria = $this->criteriaBuilder->handleRequest(
            $request,
            $criteria,
            $this->registry->getByEntityName('product'),
            $context->getContext()
        );

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

        $this->eventDispatcher->dispatch(
            new ProductSearchCriteriaEvent($request$criteria$context),
            ProductEvents::PRODUCT_SEARCH_CRITERIA
        );

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

        
/** * @dataProvider searchSortingProvider * * @group slow * * @param array<string, string> $expectedFields */
    public function testSearchSorting(array $expectedFields, Request $request): void
    {
        $criteria = new Criteria();
        $event = new ProductSearchCriteriaEvent($request$criteria, Generator::createSalesChannelContext());
        $this->eventDispatcher->dispatch($event);

        $sortings = $criteria->getSorting();

        static::assertCount(\count($expectedFields)$sortings);

        foreach ($sortings as $sorting) {
            static::assertArrayHasKey($sorting->getField()$expectedFieldsprint_r($expectedFields, true));
            static::assertSame($sorting->getDirection()$expectedFields[$sorting->getField()]);
        }
    }

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