| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | namespace CommerceLeague\ActiveCampaign\Console\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use CommerceLeague\ActiveCampaign\MessageQueue\Topics; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Quote\Collection as QuoteCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Magento\Framework\Console\Cli; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Magento\Framework\MessageQueue\PublisherInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Symfony\Component\Console\Exception\RuntimeException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Console\Helper\ProgressBarFactory; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * Class ExportAbandonedCartCommand | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class ExportAbandonedCartCommand extends AbstractExportCommand | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     private const NAME = 'activecampaign:export:abandoned-cart'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private const QUOTE_ID = 'quote-id'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private const OPTION_OMITTED = 'omitted'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     private const OPTION_ALL = 'all'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @var QuoteCollectionFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     private $quoteCollectionFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param QuoteCollectionFactory $quoteCollectionFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @param ProgressBarFactory $progressBarFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @param PublisherInterface $publisher | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         QuoteCollectionFactory $quoteCollectionFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         ProgressBarFactory $progressBarFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         PublisherInterface $publisher | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->quoteCollectionFactory = $quoteCollectionFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         parent::__construct($progressBarFactory, $publisher); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     protected function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->setName(self::NAME) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ->setDescription('Export abandoned carts') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 self::QUOTE_ID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 InputOption::VALUE_REQUIRED, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 'The quote id' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             ->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 self::OPTION_OMITTED, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 InputOption::VALUE_NONE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 'Only export omitted abandoned carts' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             ->addOption( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 self::OPTION_ALL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 InputOption::VALUE_NONE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 'Export all abandoned carts' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     protected function interact(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $quoteId = $input->getOption(self::QUOTE_ID); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $omitted = $input->getOption(self::OPTION_OMITTED); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $all = $input->getOption(self::OPTION_ALL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         if ($quoteId === null && $omitted === false && $all === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             throw new RuntimeException('Please provide at least one option'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         if ($quoteId !== null && ($omitted === true || $all === true)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             throw new RuntimeException('You cannot use --quote-id together with another option'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         if ($omitted === true && $all === true) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             throw new RuntimeException('You cannot use --omitted and --all together'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @param InputInterface $input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @param OutputInterface $output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @return int|void|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @throws \Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $quoteIds = $this->getQuoteIds($input); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $quoteIdsCount = count($quoteIds); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         if ($quoteIdsCount === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             $output->writeln('<error>No abandoned cart(s) found matching your criteria</error>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             return Cli::RETURN_FAILURE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $progressBar = $this->createProgressBar( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             $output, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             $quoteIdsCount, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             'Abandoned Cart(s)' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         foreach ($quoteIds as $quoteId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             $this->publisher->publish( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                 Topics::QUOTE_ABANDONED_CART_EXPORT, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                 json_encode(['quote_id' => $quoteId]) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             $progressBar->advance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $output->writeln(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $output->writeln(sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 '<info>%s abandoned cart(s) have been scheduled for export.</info>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                 ($quoteIdsCount) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         return Cli::RETURN_SUCCESS; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * @param InputInterface $input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      * @throws \Exception | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 141 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |     private function getQuoteIds(InputInterface $input): array | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |         /** @var QuoteCollection $quoteCollection */ | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |         $quoteCollection = $this->quoteCollectionFactory->create(); | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |         $quoteCollection->addAbandonedFilter(); | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |         if (($quoteId = $input->getOption(self::QUOTE_ID))) { | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |             $quoteCollection->addIdFilter((int)$quoteId); | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |         if ($input->getOption(self::OPTION_OMITTED)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |             $quoteCollection->addOmittedFilter(); | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |         return $quoteCollection->getAllIds(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 158 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 159 |  |  |  | 
            
                        
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