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


Add this to <a> tags href

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

Then in your controller add

 public function emptyCartAction()
| improve this answer | |
  • Do he need empty cart method or he need to empty cart after user back from checkout page automatically – Vaibhav Ahalpara Oct 10 '17 at 7:13
  • Its working bro – Ramesh S Oct 10 '17 at 7:21
  • @vaibhav as per OP's comment , he need it in hyperlink – Piyush Oct 10 '17 at 7:30

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')

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/

| improve this answer | |
  • you can upvote if you like and mask as solution if it's work for you – Vaibhav Ahalpara Oct 10 '17 at 7:18

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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