diff --git a/Helpers/BulkActions.php b/Helpers/BulkActions.php
index 9e2ab9d..f5458d3 100755
--- a/Helpers/BulkActions.php
+++ b/Helpers/BulkActions.php
@@ -154,14 +154,34 @@ private function bulkSyncAction($order, $_additionalData)
*/
private function bulkShipAction($order, $additionalData)
{
+ if ($this->configProvider->getCronOrderStatus() &&
+ $this->configProvider->getCronOrderStatus() !== $order->getStatus()
+ ) {
+ $this->monduFileLogger->info(
+ 'Order '. $order->getIncrementId() .
+ ' is not in '. $this->configProvider->getCronOrderStatus(). ' status yet. Skipping',
+ );
+
+ return null;
+ }
+
$withLineItems = $additionalData['withLineItems'] ?? false;
$monduLogData = $this->getMonduLogData($order);
+
+ if ($monduLogData['mondu_state'] === 'shipped') {
+ $this->monduFileLogger->info(
+ 'Order '. $order->getIncrementId() .
+ ' is already in state shipped. Skipping',
+ );
+ return null;
+ }
+
$this->monduFileLogger->info(
'Order ' . $order->getIncrementId() .
' Trying to create invoice, entering shipOrder'
);
- if (!$this->configProvider->isInvoiceRequiredForShipping()) {
+ if (!$this->configProvider->isInvoiceRequiredCron()) {
return $this->shipOrderWithoutInvoices($order);
} elseif ($monduInvoice = $this->shipOrder($monduLogData, $order, $withLineItems)) {
$this->monduFileLogger->info(
diff --git a/Model/Ui/ConfigProvider.php b/Model/Ui/ConfigProvider.php
index 8b4782d..1a2371c 100644
--- a/Model/Ui/ConfigProvider.php
+++ b/Model/Ui/ConfigProvider.php
@@ -179,6 +179,26 @@ public function isCronEnabled(): bool
return (bool) $this->scopeConfig->getValue('payment/mondu/cron');
}
+ /**
+ * Order status for which the Cron job will process the order
+ *
+ * @return string
+ */
+ public function getCronOrderStatus(): ?string
+ {
+ return $this->scopeConfig->getValue('payment/mondu/cron_status');
+ }
+
+ /**
+ * Is Invoice required for processing the order by the Cron job
+ *
+ * @return bool
+ */
+ public function isInvoiceRequiredCron(): bool
+ {
+ return (bool) $this->scopeConfig->getValue('payment/mondu/cron_require_invoice');
+ }
+
/**
* Get invoice url for order
*
diff --git a/Setup/Patch/Data/CronJobPatch.php b/Setup/Patch/Data/CronJobPatch.php
new file mode 100644
index 0000000..dece6fe
--- /dev/null
+++ b/Setup/Patch/Data/CronJobPatch.php
@@ -0,0 +1,63 @@
+moduleDataSetup = $moduleDataSetup;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function apply()
+ {
+ $this->moduleDataSetup->getConnection()->startSetup();
+
+ $previousValue = $this->moduleDataSetup->getConnection()->fetchOne('SELECT `value` FROM core_config_data WHERE path = "payment/mondu/require_invoice"');
+
+ if ($previousValue) {
+ $this->moduleDataSetup
+ ->getConnection()
+ ->delete('core_config_data', ['path = "payment/mondu/cron_require_invoice"']);
+
+ $this->moduleDataSetup->getConnection()->insert('core_config_data', [
+ 'scope' => 'default',
+ 'scope_id' => 0,
+ 'path' => 'payment/mondu/cron_require_invoice',
+ 'value' => $previousValue,
+ ]);
+ }
+
+ $this->moduleDataSetup->getConnection()->endSetup();
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public static function getDependencies()
+ {
+ return [];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+}
diff --git a/composer.json b/composer.json
index a442342..57d5662 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "mondu_gmbh/magento2-payment",
"description": "Mondu payment method for magento 2",
"type": "magento2-module",
- "version": "2.3.1",
+ "version": "2.3.2",
"license": [
"MIT"
],
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 60dfac5..3c700d3 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -115,12 +115,6 @@
Magento\Directory\Model\Config\Source\Country
payment/mondu/specificcountry
-
-
- payment/mondu/cron
- Magento\Config\Model\Config\Source\Yesno
-
@@ -128,6 +122,29 @@
Magento\Config\Model\Config\Source\Yesno
+
+
+
+
+
+ payment/mondu/cron
+ Magento\Config\Model\Config\Source\Yesno
+
+
+
+
+ payment/mondu/cron_status
+ Magento\Sales\Model\Config\Source\Order\Status
+
+
+
+
+ payment/mondu/cron_require_invoice
+ Magento\Config\Model\Config\Source\Yesno
+
+
diff --git a/etc/crontab.xml b/etc/crontab.xml
index 2cbb9d1..4e8c2fe 100644
--- a/etc/crontab.xml
+++ b/etc/crontab.xml
@@ -1,7 +1,7 @@
-
+
*/30 * * * *