All cookies accepted? Start exploring!
We use cookies to give you the best experience and to analyse how you use our website, these cookies are necessary for our website to function and cannot be switched off in our systems. We call these essential cookies as they are used to ensure site security and to provide core functionality. Without this type of technology, our website won't work properly. We also allow third parties to use tracking technologies for similar purposes. These cookies are used by social media services to enable you to share our content with your friends and networks.

The XC9 Entity Composer functionality is introduced in update-2, and this article describes the concept and explains how to add Entity Composer templates using the Business Tools.

In this article we describe how to programmatically add Entity Composer templates. This is for example useful when writing your own catalog importer. Creating a template, adding it to a sellable item, and filling a property value requires the following steps:
 
  • Create an Entity Composer template
  • Add an item definition to the catalog
  • Link template to an item definition
  • Set a property value for a sellable item
  • Link the entity view to the Entity Composer template
The next sections describe each step in detail.
 

Create an Entity Composer template

First step is to create a template, named "My example template", and make it visible in the Business Tools by adding it to the proper list. The template has one property named "My example property".
 

 
Note that Entity Composer templates are stored in the CommerceEntities table (of the SharedEnvironments database). Above code was largely reverse-engineered from the Sitecore.Commerce.Plugin.Composer.ComposerCommander class.
 

Add an item definition to the catalog

To link the template to a sellable item we will use the item definition approach. For this we first need to indicate on the catalog which item definitions are allowed.



Link template to item definition
Now link the template to the newly created Item Definition.


 

Set a property value for a sellable item

To add a property value for the linked template we need to:
 
  • create an entity view with the same name as the
  • template, add a property with matching name, and add it
  • to the sellable item

Link the entity view to the Entity Composer template

The final step is to track which entity view belongs to which composer template.
 

Remarks

The Entity Composer functionality is brand new, and while reverse engineering how to programmatically do it, we bumped into some (to be solved) unclearities and bugs:
 
  • Property values cannot be set for product variants. The CatalogDataProvider however generates templates for variants, and somehow some values get filled. This is a limitation of the current implementation in XC9 update-2.
  • The CatalogDataProvider throws an error when properties do not have RawValue set (in JSON). As a result you will not see any values in the Sitecore Content Editor. Workaround is either always filling a value, or patching CatalogDataProvider.GetItemFields with following code (see this post):
 
  • Circular template inheritance error; the generated template inherits from its self. This is not a blocking issue, but to be solved and probably closely related to the template shown twice issue.

Articles related to this topic

Share a Tweet
Share
or
Share