|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Sylius\SyliusShopApiPlugin\Handler; |
|
6
|
|
|
|
|
7
|
|
|
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; |
|
8
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
9
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
10
|
|
|
use Sylius\Component\Core\Repository\OrderRepositoryInterface; |
|
11
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
|
12
|
|
|
use Sylius\ShopApiPlugin\Command\PickupCart; |
|
13
|
|
|
use Webmozart\Assert\Assert; |
|
14
|
|
|
|
|
15
|
|
|
final class PickupCartHandler |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var FactoryInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
private $cartFactory; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var OrderRepositoryInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
private $cartRepository; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var ChannelRepositoryInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $channelRepository; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param FactoryInterface $cartFactory |
|
34
|
|
|
* @param OrderRepositoryInterface $cartRepository |
|
35
|
|
|
* @param ChannelRepositoryInterface $channelRepository |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(FactoryInterface $cartFactory, OrderRepositoryInterface $cartRepository, ChannelRepositoryInterface $channelRepository) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->cartFactory = $cartFactory; |
|
40
|
|
|
$this->cartRepository = $cartRepository; |
|
41
|
|
|
$this->channelRepository = $channelRepository; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param PickupCart $pickupCart |
|
46
|
|
|
*/ |
|
47
|
|
|
public function handle(PickupCart $pickupCart) |
|
48
|
|
|
{ |
|
49
|
|
|
/** @var ChannelInterface $channel */ |
|
50
|
|
|
$channel = $this->channelRepository->findOneByCode($pickupCart->channelCode()); |
|
51
|
|
|
|
|
52
|
|
|
Assert::notNull($channel, sprintf('Channel with %s code has not been found.', $pickupCart->channelCode())); |
|
53
|
|
|
|
|
54
|
|
|
/** @var OrderInterface $cart */ |
|
55
|
|
|
$cart = $this->cartFactory->createNew(); |
|
56
|
|
|
$cart->setChannel($channel); |
|
57
|
|
|
$cart->setCurrencyCode($channel->getBaseCurrency()->getCode()); |
|
58
|
|
|
$cart->setLocaleCode($channel->getDefaultLocale()->getCode()); |
|
59
|
|
|
$cart->setTokenValue($pickupCart->orderToken()); |
|
60
|
|
|
|
|
61
|
|
|
$this->cartRepository->add($cart); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|