Area: Optimizely Commerce
Applies to versions: 11 and higher
Other versions:

Bundles and packages

Recommended reading 

This topic describes how to work with bundles and packages with relation to the Commerce content model. For an introduction to these concepts, see Packages and bundles.

How it works

  • The EPiServer.Commerce.Catalog.Linking.BundleEntry class represents bundle entries.
  • The EPiServer.Commerce.Catalog.Linking.PackageEntry class represents package entries.
  • The EPiServer.Commerce.Catalog.Linking.IRelationRepository service administers each.

The Child property of the BundleEntry or PackageEntry contains the ContentReference of the entry included in the bundle/package. The class also has a SortOrder property for ordering the entries, a GroupName property for grouping entries, and a Quantity property containing the quantity of the entry in the bundle/package.

EPiServer.Commerce.Catalog.Linking.EntryRelation contains the following default values: DefaultGroupName and DefaultQuantity.

A BundleEntry or PackageEntry is uniquely defined by the ContentReference in its Child property together with its Parent property (referencing the bundle or package itself). That is, you cannot add the same entry more than once to the same bundle or package.

Getting the entries of a bundle/package

To get bundle/package entries, call the GetChildren method of IRelationRepository with the ContentReference of a bundle/package.

Getting the bundle/package by an entry

To get the packages/bundles, call the GetParents method of IRelationRepository with the ContentReference of a catalog entry.

Or, you can get the bundle/package links from a child item via entry content extensions:

Adding an entry to a bundle/package

To add new BundleEntry or PackageEntry objects to a bundle or package, use the UpdateRelations method or UpdateRelation extension method of IRelationRepository. The new entry must have a Child ContentReference, a Parent ContentReference, and you probably want to specify a Quantity and Group.

Updating an entry in a bundle/package

To update BundleEntry or PackageEntry objects, such as updating the Quantity, use the UpdateRelations method or the UpdateRelation extension method of IRelationRepository. You can construct a new object to replace the old one (matched by the Parent and Child properties). Or, use GetParents to get the existing Relations, filter out the object you want to update, and pass it to UpdateRelation after changing the value.

Removing an entry from a bundle/package

To remove an entry from a bundle/package, call the RemoveRelations method or RemoveRelation extension method of IRelationRepository with a BundleEntry or PackageEntry object matching an existing bundle/package entry. You can construct a matching object, or use GetParents to get the existing Relations, to filter out the object you want to remove and pass it to RemoveRelation.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 24, 2016

Recommended reading