AutoOrderCancel (optional)
GitHub - magesuite/auto-order-cancel
This module adds the possibility to cancel bank transfer orders after a given period.
Â
Installation
This module is optional.
composer require "creativestyle/magesuite-auto-order-cancel" ^1.0.0
Admin settings
Admin settings for the module are placed in Stores -> Configuration -> MageSuite -> Auto order cancel
Settings:
Field | Options | Comment |
---|---|---|
Enable cancellation of unpaid orders |  Yes/No | Disabled by default |
Payment Methods | List of payment methods available in the shop | Please select the bank transfer methods to auto cancel. |
Time to cancel orders (days) | number | Number of days after which an unpaid order will be canceled, default: 7 |
Cancel orders cron schedule | crone schedule | Enter crone schedule, default: 30 3 * * * |
Backend
Add documentation for BE code
Cron runs execute
method in file vendor/creativestyle/magesuite-auto-order-cancel/Cron/CancelOrders.php
class CancelOrders
{
public function execute()
{
.....
$orderCanceller->execute();
}
}
Â
It runs also execute
method in service vendor/creativestyle/magesuite-auto-order-cancel/Service/OrderCanceller.php
It calls method cancelUnpaidOrders
where:
we get collection with orders which need to be canceled
than for each order all invoices are canceled and than given order is canceled
Â
class OrderCanceller
{
public function execute():void
{
foreach ($this->storeManager->getStores() as $store) {
.....
$this->cancelUnpaidOrders($storeId);
}
}
public function cancelUnpaidOrders(?int $storeId = null):void
{
$orders = $this->ordersToCancelCollection->getOrders($storeId);
foreach ($orders as $order) {
.....
$this->cancelInvoices($order);
$this->orderManagement->cancel($order->getEntityId());
.....
}
}
protected function cancelInvoices(\Magento\Sales\Model\Order $order):void
{
foreach ($order->getInvoiceCollection() as $invoice) {
$invoice->cancel();
.....
}
}
}
Frontend
The module does not provide any functionality for the storefront.