Developer forum

Forum » Ecommerce - Standard features » Clear cart when browser is cleared

Clear cart when browser is cleared

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I have a solution where "Days the cart is saved" is set to 0. Yet when I log in, add items to the cart, close all active browser windows and then log in again, I still see my old cart. Shoudn't a value of zero prevent the cart from being saved and reassociated with my logged in account? Is there another way to clear the cart when you log out or close your browser? (I suppose I could set the cart to a new Cart in Session_Start but wondered if there's a beter way).

Thanks,

Imar


Replies

 
Nicolai Høeg Pedersen
Reply

That setting is for carts for anonymous visitors - it is the cookie (I think 0 means 1 year as that is default).

If you are a known user DW will remember it forever. So best option is to empty the cart on login (you cannot be sure they logoff)

Maybe this setting will work as well. But I do not know how it works if you do not have a cart before you login.

BR Nicolai

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Yeah, that's what I ended up doing. I am calling this:

      Context.SetCart(new Dynamicweb.eCommerce.Orders.Order());


from both Session_Start (for when you close your broser) and from Notifications.Standard.User.OnBeforeExtranetLogOff (in case you log off but leave your browser open).

Does that look like the right way to do it?

Imar

 
Nicolai Høeg Pedersen
Reply

Should be ok!

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hmmm, that doesn't work too well. I now end up with hundreds of empty, red orders (with an ID like ORDER123) in the backend; I assume one for each time the code above is called.

Should I clear the cart instead? Is calling OrderLines.Clear() followed by Save a good idea?

Imar

 

You must be logged in to post in the forum