Copied to clipboard

Flag this post as spam?

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


  • Kenni Rau 8 posts 109 karma points
    Mar 01, 2021 @ 12:22
    Kenni Rau
    0

    Custom order properties

    I'm in need of an array property on an order which contains objects. I have tried to add the property with the following code:

    order.properties['productDetailsList'] = order.properties['productDetailsList'] ||  {
        value: [],
        isReadOnly: false,
        isServerSideOnly: false
    };
    
    vm.tempSeriesEntry = {
        sku: "SKU1337",
        seriesNumber: "SERNUM1337",
        isReturned: false
    };
    
    order.properties['productDetailsList'].value.push(vm.tempSeriesEntry);
    

    I see the property correct when I log the order.properties object, but when I try to save the order I get the following error: Failed to save order: The request is invalid.

    I have tried to change to value to bool, int og string and it works just fine. Is it not possible to have an array as the value?

  • Matt Brailsford 2958 posts 15629 karma points MVP 7x c-trib
    Mar 01, 2021 @ 13:45
    Matt Brailsford
    100

    Hi Kenni,

    All properties are currently stored as strings so you'd need to serialize / deserialize the array when setting / getting the property value.

    We have an enhancement request to make this more strongly typed, but it isn't something we currently have in place so for the time being, you'll need to handle the conversion yourself.

    Maybe wrapping the code in an extension method for the time being would do the trick.

    public static class OrderExtensions
    {
         public static List<SeriesEntry> GetProductDetails(this OrderReadOnly order) 
            => JsonConvert.DeserializeObject<List<SeriesEntry>>(order.properties['productDetailsList']);
    
        public static void SetProductDetails(this Order order, List<SeriesEntry> entries) 
            => order.SetProperty("productDetailsList", JsonConvert.SerializeObject(entries));
    
    }
    

    Hope this helps

    Matt

  • Kenni Rau 8 posts 109 karma points
    Mar 02, 2021 @ 08:40
    Kenni Rau
    1

    Hey Matt,

    I'll just serialize and deserialize then, thanks ;)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies