custom/plugins/MoorlFoundation/src/Core/Content/Product/SalesChannel/Search/FoundationProductSearchRoute.php line 36

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlFoundation\Core\Content\Product\SalesChannel\Search;
  3. use MoorlFoundation\Core\Service\EntitySearchService;
  4. use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingResult;
  5. use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductDefinition;
  6. use Shopware\Core\Content\Product\SalesChannel\Search\AbstractProductSearchRoute;
  7. use Shopware\Core\Content\Product\SalesChannel\Search\ProductSearchRouteResponse;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  9. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  12. class FoundationProductSearchRoute extends AbstractProductSearchRoute
  13. {
  14.     private AbstractProductSearchRoute $decorated;
  15.     private EventDispatcherInterface $dispatcher;
  16.     private EntitySearchService $searchService;
  17.     public function __construct(
  18.         AbstractProductSearchRoute $decorated,
  19.         EntitySearchService $searchService,
  20.         EventDispatcherInterface $dispatcher
  21.     ) {
  22.         $this->decorated $decorated;
  23.         $this->dispatcher $dispatcher;
  24.         $this->searchService $searchService;
  25.     }
  26.     public function getDecorated(): AbstractProductSearchRoute
  27.     {
  28.         return $this->decorated;
  29.     }
  30.     public function load(Request $requestSalesChannelContext $contextCriteria $criteria): ProductSearchRouteResponse
  31.     {
  32.         $entityListing $this->searchService->getEntityListing($request$context->getContext());
  33.         if ($entityListing && $entityListing->getEntityName() !== SalesChannelProductDefinition::ENTITY_NAME) {
  34.             $entityListing->setEventDispatcher($this->dispatcher);
  35.             $entityListing->setRequest($request);
  36.             $entityListing->setSalesChannelContext($context);
  37.             $result $entityListing->listingRoute($criteria)->getResult();
  38.             $result ProductListingResult::createFrom($result);
  39.             $result->addCurrentFilter('search'$request->query->get('search'));
  40.             return new ProductSearchRouteResponse($result);
  41.         }
  42.         return $this->decorated->load($request$context$criteria);
  43.     }
  44. }