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

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\Framework\Routing\Annotation\RouteScope;
  10. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  13. /**
  14.  * @RouteScope(scopes={"store-api"})
  15.  */
  16. class FoundationProductSearchRoute extends AbstractProductSearchRoute
  17. {
  18.     private AbstractProductSearchRoute $decorated;
  19.     private EventDispatcherInterface $dispatcher;
  20.     private EntitySearchService $searchService;
  21.     public function __construct(
  22.         AbstractProductSearchRoute $decorated,
  23.         EntitySearchService $searchService,
  24.         EventDispatcherInterface $dispatcher
  25.     ) {
  26.         $this->decorated $decorated;
  27.         $this->dispatcher $dispatcher;
  28.         $this->searchService $searchService;
  29.     }
  30.     public function getDecorated(): AbstractProductSearchRoute
  31.     {
  32.         return $this->decorated;
  33.     }
  34.     public function load(Request $requestSalesChannelContext $contextCriteria $criteria): ProductSearchRouteResponse
  35.     {
  36.         $entityListing $this->searchService->getEntityListing($request$context->getContext());
  37.         if ($entityListing && $entityListing->getEntityName() !== SalesChannelProductDefinition::ENTITY_NAME) {
  38.             $entityListing->setEventDispatcher($this->dispatcher);
  39.             $entityListing->setRequest($request);
  40.             $entityListing->setSalesChannelContext($context);
  41.             $result $entityListing->listingRoute($criteria)->getResult();
  42.             $result ProductListingResult::createFrom($result);
  43.             $result->addCurrentFilter('search'$request->get('search'));
  44.             return new ProductSearchRouteResponse($result);
  45.         }
  46.         return $this->decorated->load($request$context$criteria);
  47.     }
  48. }