1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,97 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+declare(strict_types=1); |
|
4 |
+ |
|
5 |
+/* |
|
6 |
+ * This file is part of vonRotenberg WMFGO Cevisio Bundle. |
|
7 |
+ * |
|
8 |
+ * (c) vonRotenberg |
|
9 |
+ * |
|
10 |
+ * @license proprietary |
|
11 |
+ */ |
|
12 |
+ |
|
13 |
+namespace vonRotenberg\WmfgoCevisioBundle\Command; |
|
14 |
+ |
|
15 |
+use Contao\CoreBundle\Framework\ContaoFramework; |
|
16 |
+use Contao\System; |
|
17 |
+use Symfony\Component\Console\Command\Command; |
|
18 |
+use Symfony\Component\Console\Input\InputInterface; |
|
19 |
+use Symfony\Component\Console\Input\InputOption; |
|
20 |
+use Symfony\Component\Console\Output\OutputInterface; |
|
21 |
+use Symfony\Component\Console\Style\SymfonyStyle; |
|
22 |
+use vonRotenberg\WmfgoCevisioBundle\Cron\ShopwareExportOrdersJob; |
|
23 |
+use vonRotenberg\WmfgoCevisioBundle\Cron\ShopwareImportProductsJob; |
|
24 |
+ |
|
25 |
+class ShopwareExportOrdersCommand extends Command |
|
26 |
+{ |
|
27 |
+ protected static $defaultName = 'shopware:export-orders'; |
|
28 |
+ |
|
29 |
+ /** |
|
30 |
+ * @var ContaoFramework |
|
31 |
+ */ |
|
32 |
+ private $framework; |
|
33 |
+ |
|
34 |
+ private $start; |
|
35 |
+ private $stop; |
|
36 |
+ |
|
37 |
+ public function __construct(ContaoFramework $framework) |
|
38 |
+ { |
|
39 |
+ $this->framework = $framework; |
|
40 |
+ |
|
41 |
+ parent::__construct(); |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ protected function configure(): void |
|
45 |
+ { |
|
46 |
+ $this |
|
47 |
+ ->setName(self::$defaultName) |
|
48 |
+ ->addOption('start', 'b', InputOption::VALUE_REQUIRED, 'Custom start date') |
|
49 |
+ ->addOption('stop', 'x', InputOption::VALUE_REQUIRED, 'Custom stop date') |
|
50 |
+ ->setDescription('Export orders from Shopware instance') |
|
51 |
+ ; |
|
52 |
+ } |
|
53 |
+ |
|
54 |
+ protected function interact(InputInterface $input, OutputInterface $output): void |
|
55 |
+ { |
|
56 |
+ if ((null !== $input->getOption('start') && null === $input->getOption('stop')) |
|
57 |
+ || (null === $input->getOption('start') && null !== $input->getOption('stop'))) |
|
58 |
+ { |
|
59 |
+ throw new \RuntimeException('You need to provide start and stop date.'); |
|
60 |
+ } |
|
61 |
+ |
|
62 |
+ if (null !== $input->getOption('start')) { |
|
63 |
+ try { |
|
64 |
+ new \DateTime($input->getOption('start')); |
|
65 |
+ $this->start = $input->getOption('start'); |
|
66 |
+ } catch(\Exception $e) |
|
67 |
+ { |
|
68 |
+ throw new \InvalidArgumentException('Start date is invalid. Please provide an ISO date.'); |
|
69 |
+ } |
|
70 |
+ } |
|
71 |
+ |
|
72 |
+ if (null !== $input->getOption('stop')) { |
|
73 |
+ try { |
|
74 |
+ new \DateTime($input->getOption('stop')); |
|
75 |
+ $this->stop = $input->getOption('stop'); |
|
76 |
+ } catch(\Exception $e) |
|
77 |
+ { |
|
78 |
+ throw new \InvalidArgumentException('Stop date is invalid. Please provide an ISO date.'); |
|
79 |
+ } |
|
80 |
+ } |
|
81 |
+ } |
|
82 |
+ |
|
83 |
+ protected function execute(InputInterface $input, OutputInterface $output): int |
|
84 |
+ { |
|
85 |
+ $this->framework->initialize(); |
|
86 |
+ |
|
87 |
+ $io = new SymfonyStyle($input, $output); |
|
88 |
+ $io->title('Orders export from Shopware'); |
|
89 |
+ |
|
90 |
+ /** @var ShopwareExportOrdersJob $export */ |
|
91 |
+ $export = System::getContainer()->get(ShopwareExportOrdersJob::class); |
|
92 |
+ |
|
93 |
+ $export->export('cli', $this->start,$this->stop, $io); |
|
94 |
+ |
|
95 |
+ return 0; |
|
96 |
+ } |
|
97 |
+} |