From c43a18146b41281c807b958a1087bd337fad8739 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Wed, 29 Oct 2025 14:46:03 +0100 Subject: [PATCH 1/3] feat(orders): [PCMT-953] Add Magento CLI import type and limit for single order import --- Console/Command/ProcessOrdersCommand.php | 168 +++++++++++++++++++++++ Model/Import.php | 41 ++++++ 2 files changed, 209 insertions(+) create mode 100644 Console/Command/ProcessOrdersCommand.php diff --git a/Console/Command/ProcessOrdersCommand.php b/Console/Command/ProcessOrdersCommand.php new file mode 100644 index 0000000..2513a57 --- /dev/null +++ b/Console/Command/ProcessOrdersCommand.php @@ -0,0 +1,168 @@ + + * @copyright 2017 Lengow SAS + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +class ProcessOrdersCommand extends Command +{ + const INPUT_DAYS = 'days'; + const INPUT_ORDER_IDS = 'marketplace-order-ids'; + const INPUT_MARKETPLACE_NAME = 'marketplace-name'; + const INPUT_STORE_ID = 'store-id'; + const CMD_NAME = 'lengow:orders:process'; + const MEMORY_LIMIT = '1024M'; + + /** + * @var LengowImport $lengowImport + */ + private LengowImport $lengowImport; + + /** + * Constructor + */ + public function __construct( + LengowImport $lengowImport, + string $name = null + ) { + + $this->lengowImport = $lengowImport; + parent::__construct(self::CMD_NAME); + } + + /** + * Configure command options and description + */ + protected function configure() + { + $this->setName(self::CMD_NAME) + ->setDescription('Process marketplace orders with options') + ->addOption( + self::INPUT_DAYS, + null, + InputOption::VALUE_OPTIONAL, + 'Number of days to filter orders --days=5 to process orders from the last 5 days' + )->addOption( + self::INPUT_ORDER_IDS, + null, + InputOption::VALUE_OPTIONAL, + 'Comma-separated marketplace order IDs 123456,654321 for marketplace a specific marketplace and store' + )->addOption( + self::INPUT_MARKETPLACE_NAME, + null, + InputOption::VALUE_OPTIONAL, + 'Marketplace name (slug) example: amazon_fr, amazon_es, leroymerlin, manomano_fr ... required when using --marketplace-order-ids' + )->addOption( + self::INPUT_STORE_ID, + null, + InputOption::VALUE_OPTIONAL, + 'Store ID to process orders for a specific store example --store-id=1 --days=5' + ); + + parent::configure(); + } + + /** + * Execute command to process orders + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + ini_set('memory_limit', self::MEMORY_LIMIT); + $days = (float) $input->getOption(self::INPUT_DAYS); + $orderIdsInput = (string) $input->getOption(self::INPUT_ORDER_IDS); + $storeId = (int) $input->getOption(self::INPUT_STORE_ID); + $marketplaceName = (string) $input->getOption(self::INPUT_MARKETPLACE_NAME); + + if (empty($orderIdsInput) && empty($days)) { + $output->writeln('Please provide at least one parameter: --days or --marketplace-order-ids.'); + return Command::INVALID; + } + + if ($days < 0) { + $output->writeln('Please provide a valid --days parameter (float > 0).'); + return Command::FAILURE; + } + + if ($days) { + $maxDays = LengowImport::MAX_INTERVAL_TIME / (24 * 60 * 60); + if ($days > (int) $maxDays) { + $output->writeln("The maximum allowed days is $maxDays. Set to $maxDays."); + $days = $maxDays; + return Command::INVALID; + } + $output->writeln("Configured to process orders from the last $days days."); + $this->lengowImport->init( + [ + LengowImport::PARAM_TYPE => LengowImport::TYPE_MAGENTO_CLI, + LengowImport::PARAM_DAYS => $days, + LengowImport::PARAM_FORCE_SYNC => true + ] + ); + if ($storeId) { + $output->writeln("Store ID: " . $storeId . ""); + $this->lengowImport->setStoreId($storeId); + } + $this->lengowImport->exec(); + $output->writeln('LengowImport executed'); + return Command::SUCCESS; + + } + + $orderIds = []; + if ($orderIdsInput) { + $orderIds = array_map('trim', explode(',', $orderIdsInput)); + } + if (!empty($orderIds)) { + $output->writeln("Marketplace Order IDs: " . implode(', ', $orderIds) . ""); + if (empty($marketplaceName)) { + $output->writeln('Please provide the --marketplace-name parameter when using --marketplace-order-ids.'); + return Command::INVALID; + } + $output->writeln("Marketplace Name: " . $marketplaceName . ""); + + if (empty($storeId)) { + $output->writeln('Please provide the --store-id parameter when using --marketplace-order-ids.'); + return Command::INVALID; + } + $output->writeln("Store ID: " . $storeId . ""); + + + foreach ($orderIds as $orderId) { + $this->lengowImport->init( + [ + LengowImport::PARAM_TYPE => LengowImport::TYPE_MAGENTO_CLI, + LengowImport::PARAM_MARKETPLACE_SKU => $orderId, + LengowImport::PARAM_MARKETPLACE_NAME => $marketplaceName, + LengowImport::PARAM_STORE_ID => $storeId, + LengowImport::PARAM_FORCE_SYNC => true + ] + ); + $this->lengowImport->setImportOneOrder(true)->setLimit(1); + $this->lengowImport->exec(); + } + } + $output->writeln('LengowImport executed'); + + return Command::SUCCESS; + } +} diff --git a/Model/Import.php b/Model/Import.php index 8519897..ad0b702 100644 --- a/Model/Import.php +++ b/Model/Import.php @@ -79,6 +79,7 @@ class Import public const TYPE_MANUAL = 'manual'; public const TYPE_CRON = 'cron'; public const TYPE_MAGENTO_CRON = 'magento cron'; + public const TYPE_MAGENTO_CLI = 'magento cli'; public const TYPE_TOOLBOX = 'toolbox'; /* Import Data */ @@ -467,6 +468,46 @@ public function exec(): array return $result; } + /** + * Set store id for import + */ + public function setStoreId(int $storeId): self + { + $this->storeId = $storeId; + + return $this; + } + + /** + * Set days for order synchronisation + */ + public function setDays(float $days): self + { + $this->setIntervalTime($days); + + return $this; + } + + /** + * Set debug mode for import + */ + public function setImportOneOrder(bool $importOneOrder): self + { + $this->importOneOrder = $importOneOrder; + + return $this; + } + + /** + * Set limit for import + */ + public function setLimit(int $limit): self + { + $this->limit = $limit; + + return $this; + } + /** * Set interval time for order synchronisation * From d56104b84b0e2e730ca403992f1a2f4e99c5a4fb Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Wed, 29 Oct 2025 14:49:27 +0100 Subject: [PATCH 2/3] feat(orders): [PCMT-953] add xml in di --- etc/di.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/etc/di.xml b/etc/di.xml index 65bbcee..f3f0102 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -27,6 +27,13 @@ + + + + Lengow\Connector\Console\Command\ProcessOrdersCommand + + + Lengow\Connector\Model\ResourceModel\Log\Collection From da4ae326bbb92d8b54ffaa055f1da272704ebcdf Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Wed, 29 Oct 2025 17:23:37 +0100 Subject: [PATCH 3/3] feat(orders): [PCMT-953] --- Console/Command/ProcessOrdersCommand.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Console/Command/ProcessOrdersCommand.php b/Console/Command/ProcessOrdersCommand.php index 2513a57..670d804 100644 --- a/Console/Command/ProcessOrdersCommand.php +++ b/Console/Command/ProcessOrdersCommand.php @@ -95,11 +95,13 @@ protected function execute(InputInterface $input, OutputInterface $output) if (empty($orderIdsInput) && empty($days)) { $output->writeln('Please provide at least one parameter: --days or --marketplace-order-ids.'); + return Command::INVALID; } if ($days < 0) { $output->writeln('Please provide a valid --days parameter (float > 0).'); + return Command::FAILURE; } @@ -124,6 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $this->lengowImport->exec(); $output->writeln('LengowImport executed'); + return Command::SUCCESS; } @@ -136,12 +139,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln("Marketplace Order IDs: " . implode(', ', $orderIds) . ""); if (empty($marketplaceName)) { $output->writeln('Please provide the --marketplace-name parameter when using --marketplace-order-ids.'); + return Command::INVALID; } $output->writeln("Marketplace Name: " . $marketplaceName . ""); if (empty($storeId)) { $output->writeln('Please provide the --store-id parameter when using --marketplace-order-ids.'); + return Command::INVALID; } $output->writeln("Store ID: " . $storeId . "");