Not sure if this by any means is a recommended way of doing it with the new interface based order system. But this is what I found while looking around:
if (currItem is ILineItem) { var type = OrderContext.Current.LineItemMetaClass.MetaFields[key].DataType; } // There are many more of these but here are some examples: OrderContext.Current.PurchaseOrderMetaClass.MetaFields[key].DataType; OrderContext.Current.ShoppingCartMetaClass.MetaFields[key].DataType; OrderContext.Current.OrderAddressMetaClass.MetaFields[key].DataType; OrderContext.Current.ShipmentMetaClass.MetaFields[key].DataType;
You probably already know what "currItem" is so you might not need the if-clause.
That totally worked. Thank you!
Do you think this can cause a performance issue by any means?
"Do you think this can cause a performance issue by any means?"
OrderContext.Current.LineItemMetaClass is used in the constructor of the concrete LineItem class. In other words, the MetaClass-property you used before v10 was built up using that same call to OrderContext.Current.LineItemMetaClass. :)
In either case the data seems to be cached after the first time it gets picked up from the DB. I'd assume that it's safe to say that the performance hit would be negligeble or non-existant even if you keep recalling OrderContext.Current.LineItemMetaClass.
We have soem dynamic set of properties/metafields that we want to update from code behine.
Before updating the fields we want to check the datatype, validate the data and then update the value in the field.
In episerver 10 , metafields are added in "Properties" property of each object (linetiem, catalogentry, orderform, ect) as a dictionary. So it only contains the name of the fields and value.
Is there a way to get the "datatype" of the metafield.
We had this in episerver 9 which use to work just fine
currItem.MetaClass.MetaFields[key].DataType;
We now have this, which DOSEN"t work
currItem.Properties[key].GetType();
This doesn't work. When the value is null for the given metafield it throws error.