1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Core\Content\Product\SalesChannel\Search; |
4
|
|
|
|
5
|
|
|
use Shopware\Core\Content\Product\Events\ProductSearchCriteriaEvent; |
6
|
|
|
use Shopware\Core\Content\Product\Events\ProductSearchResultEvent; |
7
|
|
|
use Shopware\Core\Content\Product\ProductEvents; |
8
|
|
|
use Shopware\Core\Content\Product\SalesChannel\Listing\Processor\CompositeListingProcessor; |
9
|
|
|
use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingFeaturesSubscriber; |
10
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry; |
11
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; |
12
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\RequestCriteriaBuilder; |
13
|
|
|
use Shopware\Core\Framework\Feature; |
14
|
|
|
use Shopware\Core\Framework\Log\Package; |
15
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelContext; |
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
18
|
|
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
19
|
|
|
|
20
|
|
|
#[Route(defaults: ['_routeScope' => ['store-api']])] |
21
|
|
|
#[Package('system-settings')] |
22
|
|
|
class ResolvedCriteriaProductSearchRoute extends AbstractProductSearchRoute |
23
|
|
|
{ |
24
|
|
|
final public const DEFAULT_SEARCH_SORT = 'score'; |
25
|
|
|
final public const STATE = 'search-route-context'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @internal |
29
|
|
|
*/ |
30
|
|
|
public function __construct( |
31
|
|
|
private readonly AbstractProductSearchRoute $decorated, |
32
|
|
|
private readonly EventDispatcherInterface $eventDispatcher, |
33
|
|
|
private readonly DefinitionInstanceRegistry $registry, |
34
|
|
|
private readonly RequestCriteriaBuilder $criteriaBuilder, |
35
|
|
|
private readonly CompositeListingProcessor $processor |
36
|
|
|
) { |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getDecorated(): AbstractProductSearchRoute |
40
|
|
|
{ |
41
|
|
|
return $this->decorated; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
#[Route(path: '/store-api/search', name: 'store-api.search', methods: ['POST'], defaults: ['_entity' => 'product'])] |
45
|
|
|
public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ProductSearchRouteResponse |
46
|
|
|
{ |
47
|
|
|
if (!$request->get('order')) { |
48
|
|
|
$request->request->set('order', self::DEFAULT_SEARCH_SORT); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$criteria->addState(self::STATE); |
52
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
53
|
|
|
$context->getContext()->addState(ProductListingFeaturesSubscriber::HANDLED_STATE); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$criteria = $this->criteriaBuilder->handleRequest( |
57
|
|
|
$request, |
58
|
|
|
$criteria, |
59
|
|
|
$this->registry->getByEntityName('product'), |
60
|
|
|
$context->getContext() |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$this->processor->prepare($request, $criteria, $context); |
64
|
|
|
|
65
|
|
|
$this->eventDispatcher->dispatch( |
66
|
|
|
new ProductSearchCriteriaEvent($request, $criteria, $context), |
67
|
|
|
ProductEvents::PRODUCT_SEARCH_CRITERIA |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$response = $this->getDecorated()->load($request, $context, $criteria); |
71
|
|
|
|
72
|
|
|
$this->processor->process($request, $response->getListingResult(), $context); |
73
|
|
|
|
74
|
|
|
$this->eventDispatcher->dispatch( |
75
|
|
|
new ProductSearchResultEvent($request, $response->getListingResult(), $context), |
76
|
|
|
ProductEvents::PRODUCT_SEARCH_RESULT |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$response->getListingResult()->addCurrentFilter('search', $request->get('search')); |
80
|
|
|
|
81
|
|
|
return $response; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.