Copied to clipboard

Flag this post as spam?

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


  • Brad Harder 6 posts 26 karma points
    Jul 12, 2016 @ 06:26
    Brad Harder
    0

    Load balanced environment and using basket

    Hi,

    Hoping that someone might be able to give me a pointer in the right direction in solving an issue I have.

    Currently the production environment consists of two load balanced webservers which house the umbraco instance with the store.

    The store operates on a shopping basket principle, and the customer details are entered only when purchasing.

    Currently there are instances where the basket contents change e.g. has three items, and you add another one and might return only 2 items or toggle between some items and no items.

    I have a believe that it might have something to do with the load balancing. Has anyone run across this, and what did you do to resolve this?

    I admit to being a merchello novice (first site constructed), here is the code that I have for adding an item to the basket, and returning the current basket.

        public JObject AddItemToBasket(Dictionary<string, string> ProductInformation) {
            string ProductKey = ProductInformation["ProductKey"];
            int Quantity = int.Parse(ProductInformation["Quantity"]);
    
            var merchello = new MerchelloHelper(false);
    
            var product = ProductsService.GetByKey(Guid.Parse(ProductKey));
    
            Basket.AddItem(product, product.Name, Quantity, SetItemExtendedData(product));
    
            Basket.Save();
            return GetBasketContents();
        }
        public JObject GetBasketContents() {
            string ProductSku = string.Empty;
            OrderResponse response = new OrderResponse();
    
            response.Status = OrderResponse.OTLOrderStatus.Success;
            response.BasketItems = Basket.Items;
    
            //Loop through each Item in the basket and add the detached data to the response
            foreach (var item in response.BasketItems) {
                ProductSku = item.Sku.ToString();
    
                if (!response.DetachedContents.ContainsKey(ProductSku)) {
                    response.DetachedContents.Add(ProductSku, GetProductDetachedContents(ProductSku));
                }
            }
    
            return JObject.FromObject(response);
        }
    

    Thanks.

  • David Peck 583 posts 1546 karma points c-trib
    Jul 12, 2016 @ 07:33
    David Peck
    0

    Every chance you're right. How are you managing the the session?

    On a load balanced server setup you most likely want to use a session state server (SQL DB) to manage the session.

  • Brad Harder 6 posts 26 karma points
    Jul 13, 2016 @ 00:04
    Brad Harder
    0

    lol.. didn't even think to check that, but when I did it was fine.

    Turns out the the "Cross-Zone" load balancing was enabled. When this was switched off, everything just started working as expected.

    Something to keep in mind for the future :)

    Thanks.

  • Daniel 6 posts 76 karma points
    Jul 19, 2016 @ 19:40
    Daniel
    0

    Hi Brad,

    I can see you are using AWS here. Have you tried with Azure? I am having the exact same problem but my cloud provider is MS Azure.

    Best, Daniel

  • Rick 89 posts 255 karma points
    6 days ago
    Rick
    0

    Sorry to hijack this thread and appreciate it's a bit old but my web searches have got me here... has anyone got Merchello working with Azure in a load balanced environment? i.e. using Redis cache and getting product changes to appear on the slave server (after making the changes in the master server).

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft