Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • luke-taylor-dev 12 posts 32 karma points
    Apr 16, 2020 @ 15:05
    luke-taylor-dev
    0

    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

  • Matt Brailsford 4123 posts 22194 karma points MVP 9x c-trib
    Apr 16, 2020 @ 15:52
    Matt Brailsford
    0

    Hey Luke

    I think calling RemoveAllOrderLines should do the trick https://docs.teacommerce.net/3.4.0/api/order-line/#removeallorderlines

    Matt

  • luke-taylor-dev 12 posts 32 karma points
    Apr 16, 2020 @ 16:03
    luke-taylor-dev
    0

    Cheers, is there a way to get the store id from a surface controller?

  • Matt Brailsford 4123 posts 22194 karma points MVP 9x c-trib
    Apr 17, 2020 @ 17:27
    Matt Brailsford
    0

    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.

    var storeId = CurrentPage.GetPropertyValue<long>("store", true);
    var currentOrder = TC.RemoveAllOrderLines(storeId);
    

    Hope this helps

    Matt

  • Francis Benyah 35 posts 111 karma points
    May 17, 2020 @ 10:33
    Francis Benyah
    0

    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

  • Matt Brailsford 4123 posts 22194 karma points MVP 9x c-trib
    May 17, 2020 @ 10:46
    Matt Brailsford
    0

    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

  • Francis Benyah 35 posts 111 karma points
    May 17, 2020 @ 11:02
    Francis Benyah
    0

    Hi Matt

    Thanks for the speedy response and feedback.

    Will change the approach as advised much appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft