[11.8.3] SaveAsPurchaseOrder does not set custom properties from cart



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. 

Some code:

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;
return cart;

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:

 public OrderMetaFieldService()
            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,

            JoinField(metaField, metaClassName);
            return metaField;

        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]

Jul 13, 2018 11:55

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

Jul 13, 2018 12:12

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. :(

Edited, Jul 13, 2018 12:21

What concerns me is that in MetaField table the definition has SystemMetaClassId set to 0 whether other, system metafields have value greater than 0:


Jul 13, 2018 12:29

Did you make sure you have exact matches between ICart properties and PurchaseOrder metafields, and between ILineItem properties and LineItem metafields?

Jul 13, 2018 13:09

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.

Jul 13, 2018 13:27
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.