Implement a custom product entity
When deciding whether to add a field to the main product template and corresponding object or whether to add it to a subitem, ask yourself whether the field applies to all products.
To extend the main product entities:
-
Create a custom template that inherits from the default product template (/sitecore/templates/CommerceConnect/Products/Product) and extends it with further fields.
-
Create a custom product class that inherits from the default
Sitecore.Commerce.Entities.Products.Productclass and extends it with further properties. -
Create a custom
ProductRepositoryclass that inherits from the defaultSitecore.Commerce.Data.Products.ProductRepositoryclass. -
Override the following two methods to save and load the extended properties. Call the base implementation of these methods:
protected override void UpdateEntityItem(Item entityItem, Product entity)protected override void PopulateEntity(Item entityItem, Product entity)
-
To update the
ProductRepositoryelement in theSitecore.Commerce.Product.configfile:- Replace the value of the attribute type with the full type name of the custom product repository class. See the following snippet with the type value in italics.
- Replace the template ID set in the subelement template. See the following snippet with the template value in italics.
-
In the
IncludeTemplatessection, update the GUID of theProductTemplateID.For more information, see Product Index.
-
In the
Commerce.Entitiessection of theSitecore.CommerceProduct.configfile, update the type attribute of the Product entity entry: -
In the
ExcludeTemplatessection of theSitecore.Commerce.Products.LuceneDefaultIndexConfiguration.configfile, update the GUID of the ProductTemplateID.For more information, see Default Index.
-
If two-way synchronizing is used, create a custom
ResolveProductChangesclass that inherits from the defaultSitecore.Commerce.Pipelines.Products.SynchronizeProductEntity.ResolveProductChangesclass.
New properties that refer to items in related repositories, such as Manufacturers, load a collection of the given type and populate the values. Some internal helper methods, such as PopulateEntityFieldCollections, are provided. The following is an example of how the Manufacturers collection is populated while loading the product entity.
Follow the same procedure for other product entities.