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?
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));
}
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:
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?
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.
Hope this helps
Matt
Hey Matt,
I'll just serialize and deserialize then, thanks ;)
is working on a reply...