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

checkoutmagento2

magentno 2 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

This is what I did:

In Magento\Quote\Model\QuoteManagement at line 550 the quote is being made inactive. So I commented out the following code:

// $quote->setIsActive(false);
// $this->eventManager->dispatch(
//     'sales_model_service_quote_submit_success',
//     [
//         'order' => $order,
//         'quote' => $quote
//     ]
// );
// $this->quoteRepository->save($quote);

This would also help you to maintain cart state if the user goes back from the payment page back to checkout page.

Related Topic