|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sylius\ShopApiPlugin\Controller\Product; |
|
4
|
|
|
|
|
5
|
|
|
use FOS\RestBundle\View\View; |
|
6
|
|
|
use FOS\RestBundle\View\ViewHandlerInterface; |
|
7
|
|
|
use Sylius\ShopApiPlugin\Model\PaginatorDetails; |
|
8
|
|
|
use Sylius\ShopApiPlugin\Query\ProductCatalogQuery; |
|
9
|
|
|
use Sylius\ShopApiPlugin\Query\ProductCatalogQueryInterface; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
13
|
|
|
|
|
14
|
|
|
final class ShowProductCatalogBySlugAction |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var ViewHandlerInterface */ |
|
17
|
|
|
private $viewHandler; |
|
18
|
|
|
|
|
19
|
|
|
/** @var ProductCatalogQueryInterface */ |
|
20
|
|
|
private $productCatalogQuery; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
ViewHandlerInterface $viewHandler, |
|
24
|
|
|
ProductCatalogQueryInterface $productCatalogQuery |
|
25
|
|
|
) { |
|
26
|
|
|
$this->viewHandler = $viewHandler; |
|
27
|
|
|
$this->productCatalogQuery = $productCatalogQuery; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function __invoke(Request $request): Response |
|
31
|
|
|
{ |
|
32
|
|
|
if (!$request->query->has('channel')) { |
|
33
|
|
|
throw new NotFoundHttpException('Cannot find product without channel provided'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$page = $this->productCatalogQuery->findByTaxonSlug( |
|
37
|
|
|
$request->attributes->get('taxonomySlug'), |
|
38
|
|
|
$request->query->get('locale'), |
|
39
|
|
|
$request->query->get('channel'), |
|
40
|
|
|
new PaginatorDetails($request->attributes->get('_route'), $request->query->all()) |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
return $this->viewHandler->handle(View::create($page, Response::HTTP_OK)); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|