I want to clear the cart on loggout, what's the best way to do this? Something like a ClearCart() method would be great if there is something like that
I think Surface Controllers should have a CurrentPage property which gets you the current page, you should then be able to get the store from the root nodes store picker property by requesting it recursively.
var storeId = CurrentPage.GetPropertyValue<long>("store", true);
var currentOrder = TC.RemoveAllOrderLines(storeId);
Remove all items from cart
I want to clear the cart on loggout, what's the best way to do this? Something like a ClearCart() method would be great if there is something like that
Hey Luke
I think calling RemoveAllOrderLines should do the trick https://docs.teacommerce.net/3.4.0/api/order-line/#removeallorderlines
Matt
Cheers, is there a way to get the store id from a surface controller?
Hey Luke,
I think Surface Controllers should have a
CurrentPage
property which gets you the current page, you should then be able to get the store from the root nodes store picker property by requesting it recursively.Hope this helps
Matt
Hi All
I just came across this while searching for a different problem.
I used
_sessionManager.ClearCurrentOrder(store.Id);
by injecting ISessionManager _sessionManager into the surface controller.
@Matt I am assuming this is also okay for clearing the cart or is the other approach the preferred?
Great product by the way. Well done.
Thanks
Hi Fancis,
ClearCurrentOrder clears the current order from the session, it doesn't remove the order lines from the order. So no, it's not a suitable alternative.
Matt
Hi Matt
Thanks for the speedy response and feedback.
Will change the approach as advised much appreciated.
is working on a reply...