Copied to clipboard

Flag this post as spam?

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


  • Neil Hodges 296 posts 892 karma points
    Dec 09, 2020 @ 13:25
    Neil Hodges
    0

    Product Bundle - Same Product Id per bundles Item not being added

    Hi

    I'm trying to bundle products together by the size of the garment. It doesn't seem to want to bundle multiple products with the same productId.

    What I have so far when adding to the basket:

     if (model.Sizes != null)
            {
                var sizes = model.Sizes.Where(x => x.Value > 0);
    
                if (sizes.Any() == true)
                {
                    var bundleId = Guid.NewGuid().ToString();
                    var indx = 0;
                    foreach (var size in sizes)
                    {
                        properties[WConstants.OrderLines.Size] = size.Key;
                        if (indx == 0)
                        {
                            TC.AddOrUpdateOrderLine(store.Id, model.ProductId, size.Value, properties, bundleIdentifier: bundleId);
                        }
                        else
                        {
                            TC.AddOrUpdateOrderLine(store.Id, model.ProductId, size.Value, properties, parentBundleIdentifier: bundleId);
                        }
    
                        indx++;
                    }
                }
            }
            else
            {
                TC.AddOrUpdateOrderLine(store.Id, model.ProductId, 1, properties);
            }
    

    This produces: enter image description here

    1) Is the first Main Product, this will be the master where the others will be bundled against.

    2) Is the last in the sequence, it seems to just add them all together and take on the last size, L, there should be 5 x XS, 5 x S, 5xM and lastly 5xL

    Ive set Product uniqueness property aliases to below: enter image description here

    Can it only bundle products of unique product ids?

  • Matt Brailsford 2889 posts 15083 karma points MVP 7x c-trib
    Dec 09, 2020 @ 13:36
    Matt Brailsford
    0

    Hi Neil,

    I think this might be a similar bug that we found in Vendr, that the bundle ID isn't taken into account for uniqueness. For a quick workaround, you could add the bundleId as a property to the order line, and then use that property as a uniqueness property too. This should then treat them as separate order lines.

    We'll need to look at making an update to take bundle ID's into account, but the above workaround should be safe to apply and it would continue to work once the fix is in place.

    Hope this helps

    Matt

  • Neil Hodges 296 posts 892 karma points
    Dec 09, 2020 @ 14:30
    Neil Hodges
    0

    HI Matt

    Ive altered the code to:

    if (model.Sizes != null)
            {
                var sizes = model.Sizes.Where(x => x.Value > 0);
    
                if (sizes.Any() == true)
                {
                    var bundleId = Guid.NewGuid().ToString();
                    properties.Add("bundleId", bundleId);
    
    
                    foreach (var size in sizes)
                    {
                        properties[WConstants.OrderLines.Size] = size.Key;
                        TC.AddOrUpdateOrderLine(store.Id, model.ProductId, size.Value, properties);
                    }
                }
            }
            else
            {
                TC.AddOrUpdateOrderLine(store.Id, model.ProductId, 1, properties);
            }
    

    So it just adds the products to the order with the 'bundleId' as a property.

    Then made sure my property type is using the unique key enter image description here

    But i seem to be getting them added together, OrderLine is set at 1.

    enter image description here

    Am I doing something wrong when AddOrUpdateOrderLine? Do they still need a bundleIdentifier?

    By the way, this is using TC 3.4.4

  • Matt Brailsford 2889 posts 15083 karma points MVP 7x c-trib
    Dec 09, 2020 @ 14:45
    Matt Brailsford
    0

    Hey Neil,

    Sorry, you still want to use the bundleId as a bundleId, but you also want to use it as a property, so you need to do both.

    Hope this helps

    Matt

  • Neil Hodges 296 posts 892 karma points
    Dec 09, 2020 @ 15:11
    Neil Hodges
    0

    Yeh tried a couple of diffrent combinations but it wont add them. It seems the Bundle and Uniqueness of the product are not being obeyed.

                if (model.Sizes != null)
            {
                var sizes = model.Sizes.Where(x => x.Value > 0);
    
                if (sizes.Any() == true)
                {
                    var bundleId = Guid.NewGuid().ToString();
                    properties.Add("bundleId", bundleId);
    
                    foreach (var size in sizes)
                    {
    
                        properties[WConstants.OrderLines.Size] = size.Key;
    
                        TC.AddOrUpdateOrderLine(store.Id, model.ProductId, size.Value, properties, bundleIdentifier: bundleId);
    
                    }
                }
            }
            else
            {
                TC.AddOrUpdateOrderLine(store.Id, model.ProductId, 1, properties);
            }
    

    enter image description here

    It just gives me 1 x OrderLine and adds all the qty together? Scratching my head with this one, not sure why it wont add them as seperate orderLines?

  • Neil Hodges 296 posts 892 karma points
    Dec 09, 2020 @ 15:25
    Neil Hodges
    0

    hmm, seems if i add another unique property it works :) enter image description here

    enter image description here

    I guess now i can just group them by the Bundle Identifier to show them as under one order :)

    Cheers Matt.

  • Matt Brailsford 2889 posts 15083 karma points MVP 7x c-trib
    Dec 09, 2020 @ 15:33
    Matt Brailsford
    0

    Hey Neil,

    It might be because they are sharing the same bundleId. You need to make sure that every call to add an order line has a unique bundleId. I think here, your bundle ID is repeated per size option.

    Matt

  • Neil Hodges 296 posts 892 karma points
    Dec 09, 2020 @ 15:49
    Neil Hodges
    0

    Yeh, I moved the generation of the bundle Identifier into the for each loop, creating a new GUID each loop.

     foreach (var size in sizes)
                    {
                        var bundleId = Guid.NewGuid().ToString();
                        properties.Add("bundleId", bundleId);
                        properties[WConstants.OrderLines.Size] = size.Key;
    
                        TC.AddOrUpdateOrderLine(store.Id, model.ProductId, size.Value, properties, bundleIdentifier: bundleId);
    
                    }
    

    But just got an error:

    An item with the same key has already been added.

    enter image description here

  • Neil Hodges 296 posts 892 karma points
    Dec 09, 2020 @ 15:52
    Neil Hodges
    0

    I guess its the

    properties.Add("bundleId", bundleId);
    

    part, as that key is already added,

    I think this would then work:

    if (sizes.Any() == true)
                {
                    var bundleIdentifier = Guid.NewGuid().ToString();
                    properties.Add("bundleId", bundleIdentifier);
    
                    foreach (var size in sizes)
                    {
                        var bundleId = Guid.NewGuid().ToString();
                        properties[WConstants.OrderLines.Size] = size.Key;
    
                        TC.AddOrUpdateOrderLine(store.Id, model.ProductId, size.Value, properties, bundleIdentifier: bundleId);
    
                    }
                }
    
  • Matt Brailsford 2889 posts 15083 karma points MVP 7x c-trib
    Dec 09, 2020 @ 15:56
    Matt Brailsford
    100

    I think really each call to TC.AddOrUpdateOrderLine should have it's own properties collection created, as currently you are reusing the properties for each call, hence the error.

    Matt

  • Neil Hodges 296 posts 892 karma points
    Dec 09, 2020 @ 16:05
    Neil Hodges
    0

    Nice one Matt, all sorted! :)

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft