Hi there!
How do I prevent items in my cart to clear after a failed payment? It seems this problem only occurs when I use Paypal's Pro Hosted solution.
precondition
Magento 2.2.2
PHP 7.0
SQL 5.7
Steps to reproduce
Expected results
Actual result
Hello @tim_muangkeo
Did you follow this blog?
http://magecomp.com/blog/prevent-magento-from-emptying-cart-after-payment-cancellation/ |
Below is the solution for magento 2.3.5
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; } }
Please mention the file path for Failure.php.
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/