November Happy Hour will be moved to Thursday December 5th.

multi-language line item metafield values are NULL when the order is retrieved through OrderContext

Vote:
 

Hi,

I've created a few multi-language metafields for line item and managed to successfully set values for all enabled languages, verified by inspecting the purchase order's line items through the Commerce Manager UI. But, when retrieving the same purchase orders through any of the metods on OrderContext, all the multi-language fields are NULL. Is there some special way that the order needs to be retrieved for the multi-language fields to be populated, or is there some other trick to this? The custom fields that are not multi-language are populated as expected.

Edit: Commerce version is 9.22.0

Regards,
Per A

#172666
Edited, Dec 07, 2016 18:00
Vote:
 

Hi,

Can you post the code you're using to load the orders?

/Q

#172672
Dec 07, 2016 22:59
Vote:
 

Hi,

I've mostly been using GetOrderByTrackingNumber in OrderRepository from the Commerce Starter Kit. I've also tried to use OrderContext directly, by calling the GetMostRecentPurchaseOrder method. 

#172674
Dec 08, 2016 0:05
Vote:
 

Hi,

I have to check for sure, but Cart/PurchaseOrder are "just another metaclasses". So if you want to load the metafields, you'll have to use MetaObject class - otherwise OrderContext will only returns the metaobject in master language.

Pseudo code:

var metaDataContext = OrderContext.MetaDataContext.Clone();

metaDataContext.UseCurrentThreadCulture = false;
metaDataContext.Language = "no";

MetaObject.Load(metaDataContext, orderId, "PurchaseOrder");


Regards,

/Q

#172685
Dec 08, 2016 9:32
Vote:
 

Awesome, that worked! :) Thanks a bunch, Quan.

I made a few extension methods to make it easier to use. Maybe they can be of use to someone else.

public static MetaDataContext GetClone(this MetaDataContext mdContext, string language)
{
    var clonedMetaDataContext = mdContext.Clone();
    clonedMetaDataContext.UseCurrentThreadCulture = false;
    clonedMetaDataContext.Language = language;

    return clonedMetaDataContext;
}
public static MetaObject LoadMetaObject(this MetaStorageBase item, MetaDataContext context)
{
    return MetaObject.Load(context, item.Id, item.MetaClass.Name);
}
#172688
Dec 08, 2016 10:19
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.