diff --git a/Console/TriggerReport.php b/Console/TriggerReport.php new file mode 100644 index 0000000..6dd42cb --- /dev/null +++ b/Console/TriggerReport.php @@ -0,0 +1,84 @@ +_config = $configFactory->create(); + $this->_reporter = $reporterFactory->create(); + parent::__construct(); + } + + protected function configure() + { + $this->addArgument( + self::INPUT_KEY_SHOPCODES, + InputArgument::IS_ARRAY | InputArgument::OPTIONAL, + 'Shop code' + ); + $this->setName(self::NAME) + ->setDescription('Send Delivery Report to SeQura'); + + parent::configure(); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $codeKeys = $input->getArgument(self::INPUT_KEY_SHOPCODES); + $output->write('Trigger Delivery Report for '); + if(count($codeKeys)<1){ + $codeKeys[0] = false; + $output->writeln('all shops'); + } else { + $output->writeln(implode(',',$codeKeys)); + } + foreach ($codeKeys as $codeKey){ + if ($results = $this->_reporter->sendOrderWithShipment($codeKey)) { + $output->writeln('Ok, report Sent!'); + foreach($results as $key => $value){ + $output->writeln($key . ' => ' . $value . ' orders sent'); + } + return; + } + $output->writeln('Ko, report was not sent!'); + } + } +} \ No newline at end of file diff --git a/Model/Reporter.php b/Model/Reporter.php index 90c00c9..dc239cf 100644 --- a/Model/Reporter.php +++ b/Model/Reporter.php @@ -59,12 +59,22 @@ public function __construct( /* * @return: int orders sent */ - public function sendOrderWithShipment() + public function sendOrderWithShipment($codeKey = false) { $ret = array(); $stores = $this->_storeManager->getStores($withDefault = false); $builder = $this->_builder; + /* @todo: Understand why without the echo executing from console gives + [Magento\Framework\Exception\SessionException] + Area code not set: Area code must be set before starting a session. + */ + echo " "; + // + foreach ($stores as $store) { + if($codeKey && $store->getCode()!==$codeKey){ + continue; + } $client = new \Sequra\PhpClient\Client( $this->_config->getCoreValue('user_name'), $this->_config->getCoreValue('user_secret'), diff --git a/etc/di.xml b/etc/di.xml index 5c603d7..08fddab 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -23,4 +23,13 @@ + + + + + + Sequra\Core\Console\TriggerReport + + +