We have set up a StringDictionary property on our variation node in Commerce, but figured it would be better to create it by code.
Is there a way to programmatically setting StringDictionary property on model for the variation?If not, since it's possible to configure it via Commerce Manager, is there a way to get the values using the catalog API?
No, unfortunately that is not supported. However you can try this approach:
It's not tested (and therefore not recommended by us), but it might work.
We have plan to support stringdictionary but it will not happen anytime soon.
Thanks for the quick answer. But since the stringdictionary type is implemented in Commerce via the back-end it must be some way of getting the values out in the view via MVC?If not with catalog API, perhaps via Metadata or some other way? If it does, i would highly appreciate some kind of example to get us further in our progress.
Thanks for the optional solution, we'll look into that aswell!
If you just want to get the StringDictionary - one of the option is the MetaObject. Once you loaded the MetaObject, you can simply have this code:
var stringDict = metaObject["<StringDictionaryMetafieldName>"] as MetaStringDictionary;
this seemed to have worked. I tried out the following code:
CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntryDto(currentContent.Code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Request));
CatalogEntryDto.CatalogEntryRow catRow = (CatalogEntryDto.CatalogEntryRow)dto.CatalogEntry.Rows;
MetaObject mo = MetaObject.Load (CatalogContext.MetaDataContext, catRow.CatalogEntryId, catRow.MetaClassId);
var stringdict = mo["StringDictionaryMetaFiledName"] as MetaStringDictionary;
where currentContent.Code is the variation code set in Commerce back-end.I also added a few nullchecks, but the main thing about the code seems to be working.Thanks for this Quan!