Get value StringDictionary type on metafield Commerce 10.4

Vote:
 

Hi,

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?

/David

#176505
Mar 20, 2017 14:36
Vote:
 

Hi,

No, unfortunately that is not supported. However you can try this approach:

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=88649

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.

Regards,

/Q

#176530
Mar 20, 2017 16:46
Vote:
 

Hi Quan,

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!

Regards
/David

#176556
Mar 21, 2017 13:56
Vote:
 

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;

#176557
Mar 21, 2017 14:13
Vote:
 

Hi,

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[0];

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!

/David

#176561
Mar 21, 2017 16:33
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.