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 587 posts 1550 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
    Dec 05, 2018 @ 16:48
    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

  • Joe 15 posts 106 karma points
    Jan 07, 2019 @ 18:44
    Joe
    0

    I made it for an online shop for an international insurance company. You may take my mechanism as a reference.

    To make it work, it may needs a change to Merchello's source code. Basically the key is to trigger Examine Indexes update on slaves. Merchello's source code have private/protected/internal handlers to update the index whenever there is product update, but they changes the CMS instance only, but not the slaves. You need to make use of these handlers, think of some mechanism to trigger them in salve instances as well when there's product update.

    What I did is to change private/internal methods/models of Merchello to public, then write a Merchello Plugin to the modified Merchello make it support cloud multiple instance environment. You can try in the same way, but it certainly take timeeeeeeeeeeee.....

    p.s. Changing private/internal methods to public aims to expose these useful methods to my plugins, so I don't need to pollute merchello's source code too much, but putting my code as plugin.

Please Sign in or register to post replies

Write your reply to:

Draft