Try our conversational search powered by Generative AI!

How to add StringDictionary to commerce from code

Vote:
 

Hi

i have added new property of type PropertyDictionaryMultiple and now i need to add 500 choosable items to it and really dont want to do it manually.. 

[Display(Name = "my special property", GroupName = GroupNames.Categoriestab, ,Order = 1400)]
[BackingType(typeof(PropertyDictionaryMultiple))]
public override ItemCollection AccessProperties { get; set; }

is there a way to populate them from code?

Regards
Pawel

#143137
Jan 13, 2016 13:57
Vote:
 

by populating i mean addind them to the system so that they are choosable on variants :)

#143143
Jan 13, 2016 14:45
Vote:
 

Hi,

StringDictionary is not supported by strongly typed content type currently. Gatis made a custom implementation here: http://world.episerver.com/forum/developer-forum/EPiServer-Commerce/Thread-Container/2014/7/MetaDataTypeStringDictionary-from-code/  - I did not try it and I don't know if it works as you wanted, but you can try it yourself.

Regards.

/Q

#143164
Jan 14, 2016 8:29
Vote:
 

Thanks Quan, i found that one but was hoping there was a easier way to solve this today.. :)

#143192
Jan 14, 2016 13:27
Vote:
 

Quan is there a way to add  MetaDataType.EnumMultiValue from code? 

like for this one:

[Display(Name = "my special property", GroupName = GroupNames.Categoriestab, ,Order = 1400)]
[BackingType(typeof(PropertyDictionaryMultiple))]
public override ItemCollection<string> AccessProperties { get; set; }

#143193
Jan 14, 2016 16:04
Vote:
 

You should be able to use the property itself as it maps to EnumMultiValue

AccessProperties.Add(value);

#143265
Jan 18, 2016 18:41
Vote:
 

thanks all for your help :)

using Get and Store from MetaDictionaryItemStore solved my issue

this solved my issue:

MetaDictionaryItemStore newItemStore = ServiceLocator.Current.GetInstance<MetaDictionaryItemStore>();

var allItems = (IEnumerable<MetaDictionaryItemModel>)newItemStore.Get(parentCategoryId, new ItemRange()).Data;

if (!allItems.Where(s => s.DefaultValue.Equals(name)).Any())
{
var newModel = new MetaDictionaryItemModel();
newModel.DefaultValue = name;
newModel.IsInUse = true;
newModel.OwnerMetaFieldId = parentCategoryId;
newModel.Value = name;
newItemStore.Post(newModel);
}

#143439
Jan 23, 2016 12:52
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.