Enabling Commerce content selection

As EPiServer Commerce nodes, products and variations are EPiServer content, it is possible to create properties with content references to these. But by default EPiServer do not allow commerce content selection in edit mode.

I needed to create ContentReference property on the page to the EPiServer Commerce category but couldn't find a way how to enable category selection in edit mode. Drag and drop did work but for a user, it would be much simpler to select it from the list.

I remembered that there was some attribute which enabled it but I couldn't find it. So this article describes how to do it.

The solution is simple - just decorate your ContentReference property with UIHint attribute with one of the EPiServer.Commerce.UIHint values:

  • AllContent - allows selection of any content,
  • CatalogContent - allows selection of any commerce content,
  • CatalogEntry - allows selection of product or variation,
  • CatalogNode - allows selection of commerce category (node).

Your property then might look like this:

[Display(Order = 100)]
[UIHint(UIHint.CatalogNode)]
public virtual ContentReference RootCategory { get; set; }

And you can do more - limit selection to specific type with AllowedTypes attribute:

[Display(Order = 100)]
[UIHint(UIHint.CatalogNode)]
[AllowedTypes(typeof(FashionCategory))]
public virtual ContentReference RootCategory { get; set; }