|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Checkout\Cart\SalesChannel; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Cart\AbstractCartPersister; |
|
6
|
|
|
use Shopware\Core\Checkout\Cart\CartCalculator; |
|
7
|
|
|
use Shopware\Core\Checkout\Cart\CartFactory; |
|
8
|
|
|
use Shopware\Core\Checkout\Cart\Exception\CartTokenNotFoundException; |
|
9
|
|
|
use Shopware\Core\Checkout\Cart\TaxProvider\TaxProviderProcessor; |
|
10
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
11
|
|
|
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException; |
|
12
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelContext; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
15
|
|
|
|
|
16
|
|
|
#[Route(defaults: ['_routeScope' => ['store-api']])] |
|
17
|
|
|
#[Package('checkout')] |
|
18
|
|
|
class CartLoadRoute extends AbstractCartLoadRoute |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @internal |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct( |
|
24
|
|
|
private readonly AbstractCartPersister $persister, |
|
25
|
|
|
private readonly CartFactory $cartFactory, |
|
26
|
|
|
private readonly CartCalculator $cartCalculator, |
|
27
|
|
|
private readonly TaxProviderProcessor $taxProviderProcessor |
|
28
|
|
|
) { |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getDecorated(): AbstractCartLoadRoute |
|
32
|
|
|
{ |
|
33
|
|
|
throw new DecorationPatternException(self::class); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
#[Route(path: '/store-api/checkout/cart', name: 'store-api.checkout.cart.read', methods: ['GET', 'POST'])] |
|
37
|
|
|
public function load(Request $request, SalesChannelContext $context): CartResponse |
|
38
|
|
|
{ |
|
39
|
|
|
$token = $request->get('token', $context->getToken()); |
|
40
|
|
|
$taxed = $request->get('taxed', false); |
|
41
|
|
|
|
|
42
|
|
|
try { |
|
43
|
|
|
$cart = $this->persister->load($token, $context); |
|
44
|
|
|
} catch (CartTokenNotFoundException) { |
|
45
|
|
|
$cart = $this->cartFactory->createNew($token); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$cart = $this->cartCalculator->calculate($cart, $context); |
|
49
|
|
|
|
|
50
|
|
|
if ($taxed) { |
|
51
|
|
|
$this->taxProviderProcessor->process($cart, $context); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return new CartResponse($cart); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|