2

I need to cart empty when user back from checkout/onepage.

If it is possible please help me in this.

Or this is my plan

I have creating a checkout/onepage like this

enter image description here

Here i want to prevent back url in browser & when user click logo here link cart will empty

3

3 Answers 3

3

Add this to <a> tags href

<?php echo Mage::getBaseUrl('your_module/your_controller/emptyCart');?>

Then in your controller add

 public function emptyCartAction()
 {
    Mage::getSingleton('checkout/cart')->truncate();
    Mage::getSingleton('checkout/cart')->save();
    $this->_redirect('*/*/');
    return;
 }
3
  • Do he need empty cart method or he need to empty cart after user back from checkout page automatically Commented Oct 10, 2017 at 7:13
  • Its working bro
    – Ramesh S
    Commented Oct 10, 2017 at 7:21
  • @vaibhav as per OP's comment , he need it in hyperlink
    – Piyush
    Commented Oct 10, 2017 at 7:30
2

What you can do is set session variable on checkout page(using observer or override controller) using below code

$request = $this->getRequest();
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
if($module == 'checkout' && $controller == 'onepage' && $action == 'index')
{
   Mage::getSingleton('core/session')->setWasOnCheckout(true);
}
else
{
   if(Mage::getSingleton('core/session')->getWasOnCheckout())
   {
     Mage::getSingleton('checkout/cart')->truncate();
     Mage::getSingleton('checkout/cart')->save();
     Mage::getSingleton('core/session')->setWasOnCheckout(false)
   }
}

you can use below link to learn how to use this code with observer http://inchoo.net/magento/dispatching-before-and-after-events-to-magento-core-actions/

1
  • you can upvote if you like and mask as solution if it's work for you Commented Oct 10, 2017 at 7:18
1

You can use Magento's event and observer functionality to accomplish what you want.

  • Observe controller_action_layout_load_before event and call an observer function on this event.
  • In the observer's function, check the last URL by using below code:

$url = Mage::app()->getRequest()->getServer('HTTP_REFERER');

  • Now match, if it is checkout onepage URL, then use below code to empty the cart:

    Mage::getSingleton('checkout/cart')->truncate(); Mage::getSingleton('checkout/cart')->save(); return;

This method will help you even when you don't want to add a link to empty the cart.

Please let me know if it worked.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.