Stop Magento from emptying the shopping cart before payment confirmation?

datasn.io picture datasn.io · Feb 15, 2012 · Viewed 9.6k times · Source

This is one of the most vital problems I have found since I started testing Magento for my web store. It's kind of a no-brainer that it's absolutely unnecessary and harmful to sales to empty cart before payment confirmation, which unfortunately, Magento does.

If the user selects PayPal (website standard) for payment method and for some reason clicks "Back to xxxx" (your business name at PayPal) on the PayPal payment page without paying, PayPal would redirect the user back to http://www.example.com/checkout/cart/, which now is an EMPTY cart.

I think it should be after payment confirmation / PayPal IPN that the cart be empty-ed, instead of any point before that.

Even if the user wants to continue again, he or she'd be annoyed from searching and adding all the products again and would very probably just leave.

Any idea how I can work around this?

Answer

Jonathan Delgado picture Jonathan Delgado · Oct 3, 2013

This worked for me:

File: ~/app/code/core/Mage/Checkout/controllers/OnepageController.php

Replace this:

$this->getOnepage()->getQuote()->save();
/**
 * when there is redirect to third party, we don't want to save order yet.
 * we will save the order in return action.
 */
if (isset($redirectUrl)) {
    $result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

With this one:

/**
 * when there is redirect to third party, we don't want to save order yet.
 * we will save the order in return action.
 */
if (isset($redirectUrl)) {
    $result['redirect'] = $redirectUrl;
    $this->getOnepage()->getQuote()->setIsActive(1) ;
}
$this->getOnepage()->getQuote()->save();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));