Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PT-967] Improve cron job functionality #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Helpers/BulkActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 20 additions & 0 deletions Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
63 changes: 63 additions & 0 deletions Setup/Patch/Data/CronJobPatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
namespace Mondu\Mondu\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;

class CronJobPatch implements DataPatchInterface
{
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;

/**
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup
) {
$this->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 [];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
29 changes: 23 additions & 6 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,36 @@
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<config_path>payment/mondu/specificcountry</config_path>
</field>
<field id="cron" translate="label" type="select" sortOrder="16" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Enable automatic order processing</label>
<config_path>payment/mondu/cron</config_path>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="debug" translate="label" type="select" sortOrder="17" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Enable Logs</label>
<config_path>payment/mondu/debug</config_path>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="monducron" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0"
showInStore="0">
<label>Cron configuration</label>

<field id="cron" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0"
showInStore="0">
<label>Enable Cron job for sending invoices to Mondu</label>
<config_path>payment/mondu/cron</config_path>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>

<field id="monducron_status" translate="label" type="select" sortOrder="2" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Order status in which order will be processed by the Cron job</label>
<config_path>payment/mondu/cron_status</config_path>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
</field>

<field id="monducron_requireinvoice" translate="label" type="select" sortOrder="2" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Require Invoice document for processing orders</label>
<config_path>payment/mondu/cron_require_invoice</config_path>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</group>
</section>
</system>
Expand Down
2 changes: 1 addition & 1 deletion etc/crontab.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
<group id="default">
<job instance="Mondu\Mondu\Cron\Cron" method="execute" name="mondu_cron_test">
<job instance="Mondu\Mondu\Cron\Cron" method="execute" name="mondu_cron">
<schedule>*/30 * * * *</schedule>
</job>
</group>
Expand Down
Loading