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
Can you post the code you're using to load the orders?
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.
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.
var metaDataContext = OrderContext.MetaDataContext.Clone();
metaDataContext.UseCurrentThreadCulture = false;
metaDataContext.Language = "no";
MetaObject.Load(metaDataContext, orderId, "PurchaseOrder");
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;
public static MetaObject LoadMetaObject(this MetaStorageBase item, MetaDataContext context)
return MetaObject.Load(context, item.Id, item.MetaClass.Name);