Magento 1.9 – Prevent Cart from Emptying After Failed Payments

checkoutmagento-1.9paymentshopping-cart

How can I stop Magento to empty cart after the customer fails to pay with a card?

The customer can use a different card but the cart already becomes empty and he/she needs to put all the items back into card again which makes the site loose customer.

Best Answer

In your payment method's controller you'll have an action for failed/rejected/canceled orders.

Let's say it's called failAction(). Then you can add something like the following to your function.

public function failAction() {
...
    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;
    }
...
 }
Related Topic