diff --git a/Console/Command/ProcessOrdersCommand.php b/Console/Command/ProcessOrdersCommand.php
new file mode 100644
index 0000000..670d804
--- /dev/null
+++ b/Console/Command/ProcessOrdersCommand.php
@@ -0,0 +1,173 @@
+
+ * @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
*
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