cancel
Showing results for 
Search instead for 
Did you mean: 

Empty Cart upon Logout

Empty Cart upon Logout

I would like to empty the cart upon the customer logout.

How should I do that? I am totally new with the magento programming.

Appreciate if someone would reply.  

2 REPLIES

Re: Empty Cart upon Logout

You do know by default, when customer logout, the cart will be empty right? the cart items will be back only when customer re-login. I assume you just want to save an empty cart to the account when logout.

 

3 things you need to know before doing this task

1, module, model and object

you will use 2 module for this task: customer and checkout, in app/code/core/Mage, inside these 2 modules, there are customer model and cart model will help you

2, event and observer

there are all kinds of events in magento. when customer logout, magento will fire 'customer_logout' event, and you can register an observer to this event and clear cart

3, how to create your own module

 

http://magento.stackexchange.com/questions/41277/how-to-create-an-new-observer-on-the-event-catalog-...

 

alright, now in your custom module, register your observer, and that observer method should be

function clearCartBeforeLogout($observer)

{

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

}

 

be noted that if customer didn't click logout link, the cart won't be cleared.

Re: Empty Cart upon Logout

Yes I know that when the customer logout the cart reset to empty. I was referring to the customer that is already login.

Thanks for the link. I will wok on that. Man Happy