cancel
Showing results for 
Search instead for 
Did you mean: 

Cart Items are deleted after fail checkout magento2.2.1

Cart Items are deleted after fail checkout magento2.2.1

Summary of the issue


When I try to place an order with all the required information filled in and choose the mode of payment as PayUmoney payment Gateway then post click of Place order button, it redirects me to Payumoney popup. If I cancel the transaction on reaching this stage then in Magento Admin Panel it shows in an ordered list with the order payment status as"pending payment" which should not be the case. Instead, it should show canceled status without affecting the inventory.

 

precondition

Magento 2.2.1

PHP 7.0

SQL 5.7

Steps to reproduce

  1. Add item to cart
  2. Proceed to checkout
  3. Checkout using Credit/Debit card.
  4. Refresh/go back page, cancel payment, failed payment

Expected results

  1. if refreshed page/go back - item should still be in still in the cart
  2. cancel/failed payment - give options to try again or even choose a different payment method.

Actual result

  1. clears item and redirects to an empty page (nothing is in your shopping cart)
  2. URL is still cart/checkout
1 REPLY 1

Re: Cart Items are deleted after fail checkout magento2.2.1

Below is the solutions to "prevent magento 2.3.5 version from emptying cart after payment cancellation"

Please override Failure.php and change public function as below 

public function execute()
    {
       
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $_checkoutSession = $objectManager->create('\Magento\Checkout\Model\Session');
        $_quoteFactory = $objectManager->create('\Magento\Quote\Model\QuoteFactory');
        
        $order = $_checkoutSession->getLastRealOrder();
        $quote = $_quoteFactory->create()->loadByIdWithoutStore($order->getQuoteId());
        if ($quote->getId()) {
            $quote->setIsActive(1)->setReservedOrderId(null)->save();
            $_checkoutSession->replaceQuote($quote);
            $resultRedirect = $this->resultRedirectFactory->create();
            $resultRedirect->setPath('checkout/cart');
            //$this->messageManager->addWarningMessage('Payment Failed.');
            return $resultRedirect;
        }
    }