In this blog post I show one of two ways to extend commerce entities. With the Composer it is possible to extend the commerce entities without coding. I will guide you through the steps from creating the template
to the availability of the values in Sitecore.
You will find the Composer on the home screen of the business tools. With Sitecore XC 9.1 you can create new templates directly with the composer. In previous version you had to create the template from the view of your desired entity.
With the next steps we will create a template for an entity view.
Now that the template is created, we can define the properties and set constraints.
I have added three properties:
- HDR: Boolean
- Panel Type: String
- Frame Rate: Integer
As next step I will add constraints to these properties. For the string type I add a “Selection Option Constraint” to limit the possible values to “LCD”, “LED” and “OLED”. The frame rate will be limited to values between 50 and 200 with a “Min-Max Constraint”.
After you have setup the complete template you can edit the default values by choosing “Edit View” from the arrow button menu.
Linking a template to extend commerce entities
Without linking the template to a commerce entity, it will not show up anywhere. Therefore, you must define to which entities the template should be linked. You can assign the template by linking the template by Tag, Entity Type or Item Definition. Click on one of the three buttons in the details row.
Now after we have linked the template with an entity type, we can have a quick look into the Merchandising views. Open the Merchandising view and select a catalog. Navigate through the category’s and open a sellable item.
Because the item is already published, we are not able to modify the properties of our custom “Technical Details” view. Therefore, we must add a new entity version. Click on the “Plus” icon in the “Entity Versions” row. Confirm the security question and select the new version with a click on the version “2”.
After we have modified the values, we must publish this entity version. Click on the arrow button in the Summary row and select the Command “Promote to next workflow state” and confirm the popup.
The sellable item version “2” is still not published. It is now ready for review. You need to promote it again to the next workflow step. Repeat the steps from above. This time you have the Command “Approve” or “Reject” available. Select “Approve” and confirm the popup.
Now that we have set up some test data, we will have a look into Sitecore and see if we can find the new properties.
Sitecore Content Editor
Because we have not updated the data templates in Sitecore, the new properties will not show up. You can navigate to the item and have a quick look. On my installation the Sitecore content path is:
Verify that the template was generated by navigating to
Note the structure of the generated template: Template -> Base Template -> Property group -> Properties
Next step is to assign the template to our “Commerce Product” template. On my machine I had to navigate to: /sitecore/templates/Project/Sitecore/Commerce Product
Select the “Content” tab and add the generated template “Technical Details” to the selected base templates:
Because we have added the base template the values should show up in the details of the sellable item. Navigate to the sellable item and scroll down to the properties. If the default values and not the configured values show up. Click on “Refresh Commerce Cache” and select the sellable item again.
In this post we extended a sellable item with a custom view. But you can extend a lot of other entity types in the same way: Catalog, Category, Promotion Book, Promotion, PriceBook, PriceCard, Customer and Order.
It is an easy way to extend commerce entities without coding. But there are some points you must keep in mind:
- You have to create this templates manually on all commerce installations (developer PCs and Servers), or you have to implement a solution to synchronize between the environments.
- Even you can create the templates without developers, you still will need developers to display the properties.
- With a code first approach you will have more control about the views. If you later want to move form composer templates to coded views you may run into data migration scenarios.