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