Extend Expandable Enums in Episerver Commerce

casper.rasmussen/ December 29, 2016/ Episerver Commerce, Uncategorized/ 0 comments

Episerver Commerce relies on expandable enumerations to create Business Foundation definitions of important entities – such as contact groups and credit card options. You may be thinking, what does that mean?

From a helicopter perspective, it’s needed because Episerver, by default, ships with a definition of entities. Let me provide an example. Contact groups, which out-of-the-box maps to Customer, Partner and Distributor, are defined via a built in enumeration (CustomerContact.eContactGroup). It becomes expandable simply because the definition can be expanded at runtime – e.g. allowing me to add Premium as the fourth option. That’s clever and very useful in especially B2B e-commerce implementations.

How to expand ContactGroup by Code

It’s simple to automatically alter the expandable enumerations included in Episerver Commerce. All it takes is a InitializationModule, which uses Business Foundation to apply the updates.

MetaFieldType is the definition you need to alter – in this scenario, it’s ContactGroup. You can always locate the various built-in definitions by querying your [mcmd_MetaEnum] table. (or via the Commerce Manager interface)

Executing MetaEnum.AddItem, with type, value and name, expands the definition with a new option. Remember, this should only happen once to avoid constraint violations.

How to expand ContactGroup via Commerce Manager

It’s very simple.. but not recommend. I always try to minimize the need for manual steps after a release. Not including a scripted approach will require you to re-add the Premium option across all your environments.

It can be done via the “Edit Dictionary” option next to fields relying on expandable enumerations.

Leave a Comment

Your email address will not be published. Required fields are marked *

Please type the characters of this captcha image in the input box

Please type the characters of this captcha image in the input box
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>