1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SyliusCart\CartBundle\Command; |
4
|
|
|
|
5
|
|
|
use Broadway\CommandHandling\CommandBusInterface; |
6
|
|
|
use Broadway\UuidGenerator\UuidGeneratorInterface; |
7
|
|
|
use SyliusCart\Domain\Command\ClearCart; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Question\Question; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
final class ClearCartCommand extends Command |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var CommandBusInterface |
20
|
|
|
*/ |
21
|
|
|
private $commandBus; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var UuidGeneratorInterface |
25
|
|
|
*/ |
26
|
|
|
private $uuidGenerator; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param CommandBusInterface $commandBus |
30
|
|
|
* @param UuidGeneratorInterface $uuidGenerator |
31
|
|
|
*/ |
32
|
|
|
public function __construct(CommandBusInterface $commandBus, UuidGeneratorInterface $uuidGenerator) |
33
|
|
|
{ |
34
|
|
|
$this->commandBus = $commandBus; |
35
|
|
|
$this->uuidGenerator = $uuidGenerator; |
36
|
|
|
|
37
|
|
|
parent::__construct(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
protected function configure() |
44
|
|
|
{ |
45
|
|
|
$this |
46
|
|
|
->setName('sylius:cart:clear') |
47
|
|
|
->setDescription('Clear cart') |
48
|
|
|
; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
55
|
|
|
{ |
56
|
|
|
$helper = $this->getHelper('question'); |
57
|
|
|
$cartId = $helper->ask( |
58
|
|
|
$input, |
59
|
|
|
$output, |
60
|
|
|
new Question( |
61
|
|
|
sprintf('Cart id (%s): ', $this->uuidGenerator->generate()), |
62
|
|
|
$this->uuidGenerator->generate() |
63
|
|
|
) |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$clearCart = ClearCart::create($cartId); |
67
|
|
|
|
68
|
|
|
$this->commandBus->dispatch($clearCart); |
69
|
|
|
|
70
|
|
|
$output->writeln(sprintf('Cart cleared!')); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|