Copied to clipboard

Flag this post as spam?

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


  • Denford 132 posts 323 karma points
    Sep 26, 2020 @ 12:03
    Denford
    0

    Get Parent product on variant order lines

    Is there a way to either get or set the parent product on a order line set from a variant. With an order line set from a product with no variants, the productIdentifier is the main product's ID but for variant order lines it the guid for the variant and would like to be able to get the parent product or set a value on the orderline with the Id to then use to get the parent product.

    The reason for this is in the cart steps i need to get and use the some of the product properties. So with the customers products some of them have got a fag to indicate their are bulk products (sold in tonnes) so the variant are the sizes e.g. 1 tonne, 2 tonne etc.

    In the cart steps first i want to disable adjusting quantity for bulk products, and second is there is a bulk product in the cart show the bulk shipping option otherwise hide the bulk shipping option.

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Sep 28, 2020 @ 08:41
    Matt Brailsford
    100

    Hi Denford,

    Hmm, I don't think we do, but I think you could work around this with Order Line properties https://docs.teacommerce.net/3.4.0/api/order-line/#addorupdateorderline (see example two for adding an order line with some properties).

    Using this, you could set a "parentProductId" property and then you could look up the product. Or, if you just need to know if it's a bulk product, maybe store a "isBulk" property on the order line then you have no need to look up the product at all.

    Hope this helps

    Matt

  • Denford 132 posts 323 karma points
    Sep 28, 2020 @ 12:59
    Denford
    0

    Hi Matt,

    Thanks for that, looked at the example on the order-line documentation and think am trying this wrong as my custom properties are not being set.

    So just went with setting the bool direct as 1 of the properties( also saving the main products sku) like below.

    <input name="properties" value="isBulk, productSku" type="hidden" />
                    <input name="isBulk" value=" @isProductBulk" type="hidden" />
                    <input name="productSku" value=" @productCode" type="hidden" />
    

    then in the cart steps, trying to then retrieve them back like below, from the orderline, but the properties are not set.

    var isBulkProduct = false;
                            var lineBulkFlag = false;
                            if (!string.IsNullOrWhiteSpace(orderLine.Properties["isBulk"]) &&
                                bool.TryParse(orderLine.Properties["isBulk"], out lineBulkFlag))
                            {
                                isBulkProduct = lineBulkFlag;
                            }
    

    Do you have an example of how the property is actually set (given a value) or what else i need to save the value.

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Sep 28, 2020 @ 13:04
    Matt Brailsford
    0

    Hi Denford,

    I think the bit you might be missing (I'm not sure as it's not present in your code snippet) is telling the AddOrUpdateOrderLine method to expect properties

    <input name="AddOrUpdateOrderLine" value="productIdentifier, quantity, properties" type="hidden" />
    

    Notice how properties is appended to the list of params for the AddOrUpdateOrderLine command.

    Matt

  • Denford 132 posts 323 karma points
    Sep 28, 2020 @ 13:06
    Denford
    0

    Literally just saw that about a min ago and yep that was the missing piece :)

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Sep 28, 2020 @ 13:06
    Matt Brailsford
    0

    Perfect! 👍

Please Sign in or register to post replies

Write your reply to:

Draft