SetMetaFieldValue on multilanguage dictionary

Vote:
 

I am building a simple WCF service for adding products to Commerce and have ran into a problem with dictionaries. When I try to set values that are multilanguage dictionary the value is not set. On dictionaries not having the multilanguage set to true the values are set ok.

Assuming there is something "easy" I have missed but looking on all documentation I can find I can't see anything related to multilanguage dictionaries.

Using this code:

CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                CatalogContext.MetaDataContext.Language = "sv-SE";
                var serialized = new MetaObjectSerialized();
                var metaObj = MetaObject.NewObject(_metaContext, entry.CatalogEntry[0].CatalogEntryId, _metaClass.Id, "admin");
                MetaHelper.SetMetaFieldValue(_metaContext, metaObj, "DisplayName", new object[] { articleName });
                MetaHelper.SetMetaFieldValue(_metaContext, metaObj, "Description", new object[] { "Beskrivning" });

                // Add values from dynamically added MetaFields
                foreach (var item in metaValues)
                {
                    MetaHelper.SetMetaFieldValue(_metaContext, metaObj, item.Name, new object[] { item.Value });
                }

                metaObj.AcceptChanges(_metaContext);

#63160
Nov 12, 2012 13:00
Vote:
 

Even changing to this code as suggested in another post won't do anyting with the result. I now get the defaultlanguage of the catalog and any other language (which when running the code is no other) and try to add the meta values then.

var langList = new List<string> {_catalogDto.Catalog[0].DefaultLanguage};
                langList.AddRange(_catalogDto.Catalog[0].GetCatalogLanguageRows().Select(langRow => langRow.LanguageCode));

                // Save the meta data attributes associated with the catalog entry.
                CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                foreach (var lang in langList)
                {
                    CatalogContext.MetaDataContext.Language = lang;
                    var serialized = new MetaObjectSerialized();
                    var metaObj = MetaObject.NewObject(_metaContext, entry.CatalogEntry[0].CatalogEntryId, _metaClass.Id, "admin");
                    MetaHelper.SetMetaFieldValue(_metaContext, metaObj, "DisplayName", new object[] { articleName });
                    MetaHelper.SetMetaFieldValue(_metaContext, metaObj, "Description", new object[] { "Beskrivning" });

                    // Add values from dynamically added MetaFields
                    foreach (var item in metaValues)
                    {
                        MetaHelper.SetMetaFieldValue(_metaContext, metaObj, item.Name, new object[] { item.Value });
                    }

                    metaObj.AcceptChanges(_metaContext);

                    serialized.AddMetaObject(lang, metaObj);
                    newEntryRow.SerializedData = serialized.BinaryValue;
                    
                    CatalogContext.Current.SaveCatalogEntry(entry);
                }
                CatalogContext.MetaDataContext.UseCurrentUICulture = true;

#63163
Nov 12, 2012 14:13
Vote:
 

I think commerce generally uses an all-lower case on the culture, so try using all lower case.

In the second example, I wonder where your metaValues variable comes from? I think the foreach loop there simply overwrites your newly set values with the old ones because "DisplayName" and "Description" exist with their old values in the metaValues collection?

#63379
Nov 16, 2012 14:36
Vote:
 

The problem was the initalization of the MetaDatContext where the language was not set. Now I use this:

_metaContext = new MetaDataContext(GetConnectionString()) { UseCurrentUICulture = false, Language = CustomerConstants.DefaultLanguage };

Where the DefaultLanguageConstant is for this case sv-se.

The GetConnection only returns the connectionstring information

private static string GetConnectionString()
        {
            return ConfigurationManager.ConnectionStrings[CommerceConstants.EcfSqlConnection].ConnectionString;
        }

#63463
Nov 20, 2012 14:33
Vote:
 

I don't think you should have to re-instantiate the MetaDataContext. Just use CatalogContext.MetaDataContext and set UseCurrentUICulture and Language on it. Could the problem be that your _metaContext wasn't the same instance as the MetaDataContext.Current which you set the language for?

If, for some reason you really have to re-instantiate the context, you can just set CatalogContext.MetaDataContext to null and then get it again and it should re-instantiate without you having to work directly with the connection string.

#63483
Nov 20, 2012 16:22
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.