1

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

8
  • 1
    This depends on which payment module are you using for card payments... as the responsible code will probably be there Jan 7, 2019 at 10:17
  • What payment method you are using? Jan 7, 2019 at 11:59
  • @SukumarGorai I am using Midtrans: Veritrans-Payment module
    – Meera
    Jan 7, 2019 at 12:01
  • Share the link. Jan 7, 2019 at 12:02
  • @SukumarGorai github.com/veritrans/SNAP-Magento
    – Meera
    Jan 7, 2019 at 12:04

1 Answer 1

0

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!

2
  • Sorry, this code is not working for me.
    – Meera
    Jan 8, 2019 at 10:35
  • Does your page redirect to failure action? Try to add log and check if it redirects to correct action or not Jan 8, 2019 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.