I have an issue with SaveAsPurchaseOrder method. I got a cart with several Properties and try to save PurchaseOrder. The thing is that my extra properties both in IPurchaseOrder and in LineItems are lost. Please advise.
This is how I create a cart:
public ICart CreateOrder(Model.Create.Order request)
var cart = orderRepository.Value.Create(request.OrganizationId, cartName);
cart.Properties[MetaPropertiesDefinitions.Cart.CartContent.Reference] = request.Reference;
Next I want to create purchase order:
var orderReference = orderRepository.Value.SaveAsPurchaseOrder(cart);
For more context, this is how I added meta fields to Purchase Order and Cart:
metaDataContext = OrderContext.MetaDataContext;
public MetaField CreateMetaField(string metaClassNamespace, string metaClassName, string name,
MetaDataType type, int length,
bool allowNulls, bool cultureSpecific, string description = "", int decimalPrecision = 18, int decimalScale = 4)
var context = metaDataContext;
var metaField = GetMetaField(name);
if (metaField == null)
metaField = MetaField.Create(context,
private void JoinField(MetaField field, string metaClassName)
var metaClass = MetaClass.Load(metaDataContext, metaClassName);
if (IsMetaFieldNotConnected(field, metaClass))
In this case, namespace is:
public static string NamespaceName = OrderContext.Current.LineItemMetaClass.Namespace;
And class name is:
public static string ClassName = OrderContext.Current.LineItemMetaClass.Name;
[Pasting files is not allowed]
Assuming you are using the SerializableCart mode. You would have to add metafields to PurchaseOrder metaclass. You can go to Commerce Manager to make sure all needed metafields have been added to the corresponding metaclasses
Thanks for quick answer!
I'm using SerializableCart mode which works perfectly fine.
In commerce manager I can see following screen:
In my understanding everything is connected properly and yet properties are set to null for both LineItems and PurchaseOrder entities. :(
What concerns me is that in MetaField table the definition has SystemMetaClassId set to 0 whether other, system metafields have value greater than 0:
Did you make sure you have exact matches between ICart properties and PurchaseOrder metafields, and between ILineItem properties and LineItem metafields?
Thank you for your assistance and quick answers, Quan Mai!
I managed to fix it.
FYI: in my case the issue was resolved by changing MultiLanguage switch from true to false. I don't need this property to have support for multiple languages so this solves my problem.