Magento – How to prevent the cart form being empty after checkout payment failure

cartmagento2payment

I want user to keep its shopping cart after payment failure.
Cart becomes empty when cancel the payment transaction in checkout.

How should I change the Failure.php in Magento checkout module?

Best Answer

You can not prevent a cart from being empty as the cart is converted into order. You can however set the cart as active again in your failure function.

In your failure function, try adding this code -:

if(Mage::getSingleton('checkout/session')->getLastRealOrderId())
{
    $lastQuoteId = Mage::getSingleton('checkout/session')->getLastQuoteId());
    $quote = Mage::getModel('sales/quote')>load($lastQuoteId);
    $quote->setIsActive(true)->save();
}

Above code turns the previous cart/quote as active again.