Loading...
Area: Episerver Commerce
Applies to versions: 11.2 and higher
Other versions:

Categorizations

This topic describes how to work with categorizations in relation to Episerver Commerce's content model.

How it works

Categorizations are represented by the EPiServer.Commerce.Catalog.Linking.NodeRelation class and administered using the EPiServer.Commerce.Catalog.Linking.IRelationRepository service.

The Parent property of the NodeRelation contains the ContentReference of the category. You can categorize each entry and category. The class also has a SortOrder property that describes the order of the categorizations.

A NodeRelation is uniquely defined by the ContentReference in its Parent property together with its Child property (referencing the item being categorized). That is, you cannot add the same categorization more than once to an entry or another category.

[New in 11.2.0]

For categorizations of entries, you can choose to work with the NodeEntryRelation type instead of the NodeRelation type. NodeEntryRelation derives from NodeRelation and exposes the additional IsPrimary property, describing if the relation is the primary categorization for the entry or not.

While each entry can have multiple categorizations linking it to several categories, only one can be the primary relation. The primary relation specifies the entry's primary or home category. This category is used when building the entry's default hierarchical URL.

Getting the categorizations of an entry or category

To get categorizations, call the GetChildren method of IRelationRepository with the ContentReference of a entry or category.

Adding a categorization to an entry or category

To add new NodeRelation objects to an entry or category, use the UpdateRelations method or UpdateRelation extension method of ILinksRepository. The new categorization must have a Parent ContentReference and a Child ContentReference.

Removing a categorization from an entry or category

To remove a categorization, call the RemoveRelations method or RemoveRelation extension method of IRelationRepository with a NodeRelation object matching an existing categorization. You can either construct a matching object, or use GetChildren or GetParents to get the existing Relations, filter out the object you want to remove, and pass it to RemoveRelation.

Last updated: Oct 24, 2016