1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sylius\ShopApiPlugin\Controller\Cart; |
4
|
|
|
|
5
|
|
|
use FOS\RestBundle\View\View; |
6
|
|
|
use FOS\RestBundle\View\ViewHandlerInterface; |
7
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
8
|
|
|
use Sylius\Component\Core\Repository\OrderRepositoryInterface; |
9
|
|
|
use Sylius\ShopApiPlugin\Factory\CartViewFactoryInterface; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
13
|
|
|
|
14
|
|
|
final class SummarizeAction |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var OrderRepositoryInterface |
18
|
|
|
*/ |
19
|
|
|
private $cartRepository; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var ViewHandlerInterface |
23
|
|
|
*/ |
24
|
|
|
private $viewHandler; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var CartViewFactoryInterface |
28
|
|
|
*/ |
29
|
|
|
private $cartViewFactory; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param OrderRepositoryInterface $cartRepository |
33
|
|
|
* @param ViewHandlerInterface $viewHandler |
34
|
|
|
* @param CartViewFactoryInterface $cartViewFactory |
35
|
|
|
*/ |
36
|
|
|
public function __construct( |
37
|
|
|
OrderRepositoryInterface $cartRepository, |
38
|
|
|
ViewHandlerInterface $viewHandler, |
39
|
|
|
CartViewFactoryInterface $cartViewFactory |
40
|
|
|
) { |
41
|
|
|
$this->cartRepository = $cartRepository; |
42
|
|
|
$this->viewHandler = $viewHandler; |
43
|
|
|
$this->cartViewFactory = $cartViewFactory; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param Request $request |
48
|
|
|
* |
49
|
|
|
* @return Response |
50
|
|
|
*/ |
51
|
|
|
public function __invoke(Request $request) |
52
|
|
|
{ |
53
|
|
|
/** @var OrderInterface $cart */ |
54
|
|
|
$cart = $this->cartRepository->findOneBy(['tokenValue' => $request->attributes->get('token')]); |
55
|
|
|
|
56
|
|
|
if (null === $cart) { |
57
|
|
|
throw new NotFoundHttpException('Cart with given id does not exists'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $this->viewHandler->handle( |
61
|
|
|
View::create($this->cartViewFactory->create($cart, $cart->getLocaleCode()), Response::HTTP_OK) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|