1 | <?php |
||||
2 | declare(strict_types=1); |
||||
3 | /** |
||||
4 | */ |
||||
5 | |||||
6 | namespace CommerceLeague\ActiveCampaign\Console\Command; |
||||
7 | |||||
8 | use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
||||
9 | use CommerceLeague\ActiveCampaign\MessageQueue\Topics; |
||||
10 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory; |
||||
0 ignored issues
–
show
|
|||||
11 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Quote\Collection as QuoteCollection; |
||||
12 | use Magento\Framework\Console\Cli; |
||||
13 | use Magento\Framework\MessageQueue\PublisherInterface; |
||||
14 | use Symfony\Component\Console\Exception\RuntimeException; |
||||
15 | use Symfony\Component\Console\Helper\ProgressBarFactory; |
||||
0 ignored issues
–
show
The type
Symfony\Component\Consol...lper\ProgressBarFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
16 | use Symfony\Component\Console\Input\InputInterface; |
||||
17 | use Symfony\Component\Console\Input\InputOption; |
||||
18 | use Symfony\Component\Console\Output\OutputInterface; |
||||
19 | |||||
20 | /** |
||||
21 | * Class ExportAbandonedCartCommand |
||||
22 | */ |
||||
23 | class ExportAbandonedCartCommand extends AbstractExportCommand |
||||
24 | { |
||||
25 | private const NAME = 'activecampaign:export:abandoned-cart'; |
||||
26 | private const QUOTE_ID = 'quote-id'; |
||||
27 | private const OPTION_OMITTED = 'omitted'; |
||||
28 | private const OPTION_ALL = 'all'; |
||||
29 | |||||
30 | /** |
||||
31 | * @var QuoteCollectionFactory |
||||
32 | */ |
||||
33 | private $quoteCollectionFactory; |
||||
34 | |||||
35 | /** |
||||
36 | * @param ConfigHelper $configHelper |
||||
37 | * @param QuoteCollectionFactory $quoteCollectionFactory |
||||
38 | * @param ProgressBarFactory $progressBarFactory |
||||
39 | * @param PublisherInterface $publisher |
||||
40 | */ |
||||
41 | public function __construct( |
||||
42 | ConfigHelper $configHelper, |
||||
43 | QuoteCollectionFactory $quoteCollectionFactory, |
||||
44 | ProgressBarFactory $progressBarFactory, |
||||
45 | PublisherInterface $publisher |
||||
46 | ) { |
||||
47 | $this->quoteCollectionFactory = $quoteCollectionFactory; |
||||
48 | parent::__construct($configHelper, $progressBarFactory, $publisher); |
||||
49 | } |
||||
50 | |||||
51 | /** |
||||
52 | * @inheritDoc |
||||
53 | */ |
||||
54 | protected function configure() |
||||
55 | { |
||||
56 | $this->setName(self::NAME) |
||||
57 | ->setDescription('Export abandoned carts') |
||||
58 | ->addOption( |
||||
59 | self::QUOTE_ID, |
||||
60 | null, |
||||
61 | InputOption::VALUE_REQUIRED, |
||||
62 | 'The quote id' |
||||
63 | ) |
||||
64 | ->addOption( |
||||
65 | self::OPTION_OMITTED, |
||||
66 | null, |
||||
67 | InputOption::VALUE_NONE, |
||||
68 | 'Only export omitted abandoned carts' |
||||
69 | ) |
||||
70 | ->addOption( |
||||
71 | self::OPTION_ALL, |
||||
72 | null, |
||||
73 | InputOption::VALUE_NONE, |
||||
74 | 'Export all abandoned carts' |
||||
75 | ); |
||||
76 | } |
||||
77 | |||||
78 | /** |
||||
79 | * @inheritDoc |
||||
80 | */ |
||||
81 | protected function interact(InputInterface $input, OutputInterface $output) |
||||
82 | { |
||||
83 | if (!$this->configHelper->isEnabled() || !$this->configHelper->isAbandonedCartExportEnabled()) { |
||||
84 | throw new RuntimeException('Export disabled by system configuration'); |
||||
85 | } |
||||
86 | |||||
87 | $quoteId = $input->getOption(self::QUOTE_ID); |
||||
88 | $omitted = $input->getOption(self::OPTION_OMITTED); |
||||
89 | $all = $input->getOption(self::OPTION_ALL); |
||||
90 | |||||
91 | if ($quoteId === null && $omitted === false && $all === false) { |
||||
92 | throw new RuntimeException('Please provide at least one option'); |
||||
93 | } |
||||
94 | |||||
95 | if ($quoteId !== null && ($omitted === true || $all === true)) { |
||||
96 | throw new RuntimeException('You cannot use --quote-id together with another option'); |
||||
97 | } |
||||
98 | |||||
99 | if ($omitted === true && $all === true) { |
||||
100 | throw new RuntimeException('You cannot use --omitted and --all together'); |
||||
101 | } |
||||
102 | } |
||||
103 | |||||
104 | /** |
||||
105 | * @param InputInterface $input |
||||
106 | * @param OutputInterface $output |
||||
107 | * @return int|void|null |
||||
108 | * @throws \Exception |
||||
109 | */ |
||||
110 | protected function execute(InputInterface $input, OutputInterface $output) |
||||
111 | { |
||||
112 | $quoteIds = $this->getQuoteIds($input); |
||||
113 | $quoteIdsCount = count($quoteIds); |
||||
114 | |||||
115 | if ($quoteIdsCount === 0) { |
||||
116 | $output->writeln('<error>No abandoned cart(s) found matching your criteria</error>'); |
||||
117 | return Cli::RETURN_FAILURE; |
||||
118 | } |
||||
119 | |||||
120 | $progressBar = $this->createProgressBar( |
||||
121 | $output, |
||||
122 | $quoteIdsCount, |
||||
123 | 'Abandoned Cart(s)' |
||||
124 | ); |
||||
125 | |||||
126 | foreach ($quoteIds as $quoteId) { |
||||
127 | $this->publisher->publish( |
||||
128 | Topics::QUOTE_ABANDONED_CART_EXPORT, |
||||
129 | json_encode(['quote_id' => $quoteId]) |
||||
0 ignored issues
–
show
json_encode(array('quote_id' => $quoteId)) of type string is incompatible with the type array|object expected by parameter $data of Magento\Framework\Messag...herInterface::publish() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
130 | ); |
||||
131 | |||||
132 | $progressBar->advance(); |
||||
133 | } |
||||
134 | |||||
135 | $output->writeln(''); |
||||
136 | $output->writeln(sprintf( |
||||
137 | '<info>%s abandoned cart(s) have been scheduled for export.</info>', |
||||
138 | ($quoteIdsCount) |
||||
139 | )); |
||||
140 | |||||
141 | return Cli::RETURN_SUCCESS; |
||||
142 | } |
||||
143 | |||||
144 | /** |
||||
145 | * @param InputInterface $input |
||||
146 | * @return array |
||||
147 | * @throws \Exception |
||||
148 | */ |
||||
149 | private function getQuoteIds(InputInterface $input): array |
||||
150 | { |
||||
151 | /** @var QuoteCollection $quoteCollection */ |
||||
152 | $quoteCollection = $this->quoteCollectionFactory->create(); |
||||
153 | $quoteCollection->addAbandonedFilter(); |
||||
154 | |||||
155 | if (($quoteId = $input->getOption(self::QUOTE_ID))) { |
||||
156 | $quoteCollection->addIdFilter((int)$quoteId); |
||||
157 | } |
||||
158 | |||||
159 | if ($input->getOption(self::OPTION_OMITTED)) { |
||||
160 | $quoteCollection->addOmittedFilter(); |
||||
161 | } |
||||
162 | |||||
163 | return $quoteCollection->getAllIds(); |
||||
164 | } |
||||
165 | } |
||||
166 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths