6

How to prevent Magento 2.0 from emptying cart after failed payments?

I could find multiple solutions for this problem in Magento 1.X but could not find anything for 2.0

I am sure this must be a common issue with many Mangento 2.0 implementors.

Will be greatfull, if someone can suggest some solution for this problem.

  • 4
    This is not a common issue. Payment failure should never result in the cart emptying. That would only happen if the order completes and saves successfully, but something interrupts Magento from redirecting to success. If this is happening, something is wrong with your code. What payment method? Any custom code on order submit? – Ryan Hoerr May 16 '16 at 19:40
  • As @RyanH. stated, make sure the redirect isn't being interrupted after the order takes place. Check the admin panel to see if the orders are actually coming through or not. – Mat Hellums Jul 20 '16 at 0:08
0

I know in magento-1.9 version. sorry for this, if this is helps to you. try with following.

/app/code/core/Mage/Checkout/controllers/OnepageController.php this file is the actual controller file, but depends up on the payment method extensions it will change with Namespace/Modulename/Checkout/controllers/OnepageController.php

Find function saveOrderAction()

find these lines

$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));

comment this line //$this->getOnepage()->getQuote()->save(); and add below codes inside the if condition so the condition will look like ..

if (isset($redirectUrl)) {
            $result['redirect'] = $redirectUrl;
            $this->getOnepage()->getQuote()->setIsActive(1) ;
        }
    $this->getOnepage()->getQuote()->save();
   $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

This is i have done with the third party Payment extension.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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