[11.8.3] SaveAsPurchaseOrder does not set custom properties from cart

Vote:
 

Hi,

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;
orderRepository.Value.Save(cart);
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,
                    metaClassNamespace,
                    name,
                    name,
                    description,
                    type,
                    length,
                    allowNulls,
                    cultureSpecific,
                    false,
                    false);
            }

            JoinField(metaField, metaClassName);
            return metaField;
        }

        private void JoinField(MetaField field, string metaClassName)
        {
            var metaClass = MetaClass.Load(metaDataContext, metaClassName);
            if (IsMetaFieldNotConnected(field, metaClass))
            {
                metaClass.AddField(field);
            }
        }

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]

#195106
Jul 13, 2018 11:55
Vote:
 

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

#195109
Jul 13, 2018 12:12
Vote:
 

Thanks for quick answer!

I'm using SerializableCart mode which works perfectly fine.

In commerce manager I can see following screen:

https://www.screencast.com/t/4KTmnlrJ8

In my understanding everything is connected properly and yet properties are set to null for both LineItems and PurchaseOrder entities. :(

#195111
Edited, Jul 13, 2018 12:21
Vote:
 

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

https://www.screencast.com/t/diJY638PdwOU

#195112
Jul 13, 2018 12:29
Vote:
 

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

#195115
Jul 13, 2018 13:09
Vote:
 

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.

#195116
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.