Emptying cart before payment confirmation is red signal for Magento store sales. It’s really very harmful Magento default functionality but Magento still does it unfortunately. Let me explain it with an example.
Suppose you have been redirected to a payment gateway to proceed payment, but because of some reason, you click back without paying or payment gets failed. In such a case, payment gateway redirects back to Magento store shopping cart page but sadly with empty cart. Now if customer wants to continue again, it will get him annoyed of searching for products and adding them again and rather he may prefer leaving your site! Painful and costly, isn’t it?
To overcome this situation, you need to trick a code to redirect customers back to Magento stores with already filled cart with earlier selected products and options.
Below is the code to prevent Magento from Emptying Cart after Payment Cancellation:
Go to app/code/[local/community]/[namespace]/[module_name]/controller/exampleController.php and rewrite failureAction() or canceledAction() method as shown below.
1 |
<!--?php public function failureAction() { $arrParams = $this->getRequest()->getPost(); //var_dump($arrParams); exit; Mage::getModel('payucheckout/shared')->getResponseOperation($arrParams); /*MageComp HA Update Cart Start*/ $session = Mage::getSingleton('checkout/session'); $cart = Mage::getSingleton('checkout/cart'); $order = Mage::getModel('sales/order')->loadByIncrementId($order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getModel("sales/order")->getCollection()->getLastItem()->getIncrementId())); if ($order->getId()) { $session->getQuote()->setIsActive(false)->save(); $session->clear(); try { $order->setActionFlag(Mage_Sales_Model_Order::ACTION_FLAG_CANCEL, true); $order->cancel()->save(); } catch (Mage_Core_Exception $e) { Mage::logException($e); } $items = $order->getItemsCollection(); foreach ($items as $item) { try { $cart->addOrderItem($item); } catch (Mage_Core_Exception $e) { $session->addError($this->__($e->getMessage())); Mage::logException($e); continue; } } $cart->save(); } /*MageComp HA Update Cart End*/ $this->_redirect('checkout/cart'); } ?--> |
While working on a client’s site, I came to know this problem and find the solution for it. It worked pretty well for me without changing any other single part. Using this code marks current order as cancelled and restores the cart using the previous order details. Hope it will work great for you as well.
Let me know have you used this code to stop customers filling the purchase data again? Tell me how this blog affected and helped you through commenting. Queries and questions are always welcomed.
hi iam trying with this code iam getting error pls help me on this
can you please explain it briefly
what name i should add for module im new to magento