0

I am on project in which client needs to clear cart cache, means empty all cart on browser close.

Is there any event that detects browser close. or can it be done by javascript.

Please give advice.

1 Answer 1

1

You can clear the shopping cart on opening your magento website, I guess both results same thing,

Or You can use cms_page_render observer to write your function. Magento Home page is an CMS page so you can execute your observer function before loading home page CMS page.

You can use following types to clear your shopping session

Version 1:
// Empty shopping cart
Mage::getSingleton('checkout/cart')->truncate();

Version 2:
// Clear session data
Mage::getSingleton('checkout/session')->clear();

Version 3:
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->delete();
1
  • Hello @Charlie, If I use this observer then it will always clear cart session even closing browser. From 'cms_page_render' observer how can I detect that this page is opened first time after closing browser.? Or is there any observer to detect Browser Closing event.? Apr 2, 2015 at 6:29

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.