<?php declare(strict_types=1);
namespace Shopware\Core\Content\Product\SalesChannel\Search;
use Shopware\Core\Content\Product\Events\ProductSearchCriteriaEvent;
use Shopware\Core\Content\Product\ProductEvents;
use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\RequestCriteriaBuilder;
use Shopware\Core\Framework\Routing\Annotation\Entity;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\Framework\Routing\Annotation\Since;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
class ResolvedCriteriaProductSearchRoute extends AbstractProductSearchRoute
{
private AbstractProductSearchRoute $decorated;
private EventDispatcherInterface $eventDispatcher;
private DefinitionInstanceRegistry $registry;
private RequestCriteriaBuilder $criteriaBuilder;
/**
* @internal
*/
public function __construct(AbstractProductSearchRoute $decorated, EventDispatcherInterface $eventDispatcher, DefinitionInstanceRegistry $registry, RequestCriteriaBuilder $criteriaBuilder)
{
$this->decorated = $decorated;
$this->eventDispatcher = $eventDispatcher;
$this->registry = $registry;
$this->criteriaBuilder = $criteriaBuilder;
}
public function getDecorated(): AbstractProductSearchRoute
{
return $this->decorated;
}
/**
* @Since("6.2.0.0")
* @Entity("product")
* @Route("/store-api/search", name="store-api.search", methods={"POST"})
*/
public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ProductSearchRouteResponse
{
$criteria = $this->criteriaBuilder->handleRequest(
$request,
$criteria,
$this->registry->getByEntityName('product'),
$context->getContext()
);
$this->eventDispatcher->dispatch(
new ProductSearchCriteriaEvent($request, $criteria, $context),
ProductEvents::PRODUCT_SEARCH_CRITERIA
);
return $this->getDecorated()->load($request, $context, $criteria);
}
}