We found that, sometimes we run out of stock/inventory due to (pending payment) orders.
so to automatically cancel pending orders.
we have magento 1.9.2.4
We found that, sometimes we run out of stock/inventory due to (pending payment) orders.
so to automatically cancel pending orders.
we have magento 1.9.2.4
For Cancel pending orders automatically you can refer following links.
2)http://inchoo.net/magento/cancel-pending-orders/
Hope these will help you.
You can easily filter pending orders and mass cancel them or even better create an external script running with cron that makes an order collection check dates time anything you want then cancel them.
Below code worked for me.
private function cancelPendingPayments() {
$fromDate = date('Y-m-d H:i:s', strtotime('-2 hour'));
$toDate = date('Y-m-d H:i:s', strtotime(now()));
$orderCollection = Mage::getResourceModel('sales/order_collection');
$orderCollection->addFieldToFilter('status', 'pending_payment')
->addFieldToFilter('updated_at', array( 'from' => $fromDate, 'to' => $toDate, 'date' => true ))
->getSelect()
->order('entity_id')
->limit(20);
if( count( $orderCollection ) < 1 ) {
return;
}
foreach( $orderCollection as $order ) {
$difference = $this->getDifference($order);
if( ( $difference >= 30 ) && ( $difference < 45 ) ) {
$emailVariables = $this->pendingPaymentsVariables( $order );
$this->prepareEmail( Mage::getStoreConfig('clearbasket_settings/email_template/pending_payment_notify'),
$emailVariables, $emailVariables['orderdetails']['customername'], $emailVariables['orderdetails']['customeremail'] );
$history = $order->addStatusHistoryComment('Notification email sent - Cron Jobs',false);
$history->setIsCustomerNotified(false);
$order->save();
}
if( $difference > 60 ) {
if(!$order->canCancel()) {
Mage::log('Order cannot be canceled anymore.',null,"order.log");
}
else {
$order->cancel();
}
$order->setData('state', "canceled");
$order->setStatus("canceled");
$order->setData('state', Mage_Sales_Model_Order::STATE_CANCELED);
$order->setActionFlag(Mage_Sales_Model_Order::ACTION_FLAG_CANCEL, true);
Mage::log('Order cancel after : '.$difference, null, "order.log");
$history = $order->addStatusHistoryComment('Order marked as cancelled due to pending payment - Cron Jobs.', false);
$history->setIsCustomerNotified(false);
$order->save();
}
}
}
Please refer the below code link for notification emails and cron jobs. https://www.pearlbells.co.uk/cancel-pending-payments-magento/