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
Expected results
Actual result
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; } }
Hello
check the below reference to get an idea,
https://magecomp.com/blog/prevent-magento-from-emptying-cart-after-payment-cancellation/
http://ka.lpe.sh/2011/12/31/magento-getting-back-shopping-cart-items-after-order-fails/