Copied to clipboard

Flag this post as spam?

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


  • Nguyen Hien 52 posts 133 karma points
    Jan 19, 2016 @ 09:39
    Nguyen Hien
    0

    How to clear Basket when logout

    Hi Rusty, Currently I implement this code to clear basket when login/logout

    if (memberStatus != null && memberStatus.Username != login.UserName) {

                        while (this.Basket.Items.Count > 0)
                        {
                            var firstOrDefault = this.Basket.Items.FirstOrDefault();
                            if (firstOrDefault != null)
                                this.Basket.UpdateQuantity(firstOrDefault.Key, 0);
                        }
    
                        this.Basket.Save();
                    }
    

    But sometime, it show error in this image. How can I clear basket when login/logout with other customer?

    enter image description here

  • Nguyen Hien 52 posts 133 karma points
    Jan 19, 2016 @ 09:54
    Nguyen Hien
    100

    I try this.Basket.Empty() is ok?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 19, 2016 @ 17:02
    Rusty Swayne
    0

    @Nguyen,

    I think this relates to your problem with customer management. You should not need to empty the basket on customer log out as your customers should not share baskets (unless you are trying to ditch all items in the respective customer basket) then Basket.Empty() would do the trick.

    Also, how are you getting your basket reference?

    Using the extensions, it should be:

      var basket = CurrentCustomer.Basket();
    
  • Lee 1130 posts 3088 karma points
    Jan 19, 2016 @ 12:31
    Lee
    0

    Please can you mark the above answer as solved if the it works for you.

Please Sign in or register to post replies

Write your reply to:

Draft