How can I stop Magento to empty cart after the customer fails to pay with a card? I am using Midtrans: Veritrans-Payment module for payment method.
I am using Magento ver.1.9.3
Please give me a quick solution
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHow can I stop Magento to empty cart after the customer fails to pay with a card? I am using Midtrans: Veritrans-Payment module for payment method.
I am using Magento ver.1.9.3
Please give me a quick solution
You need to override the default failure action of magento 1 as your payment module didn't override it. If you check the below file:
/app/code/community/Midtrans/Snap/controllers/PaymentController.php
Locate the method or action responseAction() you can see that the code redirect user to default failure page of magento 1. So you need to override the default failure action which looks like below:
public function failureAction()
{
$lastQuoteId = $this->getOnepage()->getCheckout()->getLastQuoteId();
$lastOrderId = $this->getOnepage()->getCheckout()->getLastOrderId();
if (!$lastQuoteId || !$lastOrderId) {
$this->_redirect('checkout/cart');
return;
}
$this->loadLayout();
$this->renderLayout();
}
Replace the above code by overriding failure action with below code:
public function failureAction()
{
$lastQuoteId = $this->getOnepage()->getCheckout()->getLastQuoteId();
$lastOrderId = $this->getOnepage()->getCheckout()->getLastOrderId();
if(Mage::getSingleton('checkout/session')->getLastRealOrderId()){
if ($lastQuoteId = Mage::getSingleton('checkout/session')->getLastQuoteId()){
$quote = Mage::getModel('sales/quote')->load($lastQuoteId);
$quote->setIsActive(true)->save();
}
Mage::getSingleton('core/session')->addError(Mage::helper('module_name')->__('Inform the customer for failed transaction'));
$this->_redirect('checkout/cart'); //Redirect to cart
return;
}
if (!$lastQuoteId || !$lastOrderId) {
$this->_redirect('checkout/cart');
return;
}
$this->loadLayout();
$this->renderLayout();
}
Also comment the below line from your reponseAction():
$this->cancelAction();
Hope this helps!