In part one of this series we added a new entity to the commerce engine and gave business users the ability to maintain this entity. The example we used was a “Brand” for instance Nike, Reebok or New Balance.
In this post we will look at how we can bring the instances of the Brand entity into Sitecore as items so we can use them as content. You can then use those items to drive Brand landing pages and other client requirements.
The following is covered in this post :-
- Creating two templates to support the data provider
- Creating a data provider to expose the Brand entity as content
- Adding the new data provider to the configuration
Future posts will build on this foundation including how to use the new content in an SXA component.
The end result will look like the image at the start of the post.
Step 1 – Create the templates
- In Sitecore create two new templates
- Take note of the ids
Create the template for the new Brands Folder, this will be the container for the new items…
Create the template for the Brands themselves, this template should match the fields from the commerce entity (only has one field named Description at the moment)…
Step 2 – Create the data provider
The data provider follows the same pattern as the data provider that exposes the catalog and products as Sitecore items.
Create the project and add references
- Create a new “Class Library” project named “Sitecore.Services.Examples.DataProvider”
- Add reference to Newtonsoft.Json
- Add reference to Sitecore.Commerce.Engine.Connect
- Add reference Sitecore.Kernel
Add the configuration
- Add new folder named “Config”
- Add new .config file named “zzzzSitecore.Services.Examples.DataProvider.config”
- Copy in the following markup into the file
- Change the template ids to match the ids of your templates created earlier
Add the data provider code
- Add a new class named “ReadOnlyBrandDataProvider”
- Add the following code
Your project should look like this…
Step 3 – Deploy and test
- Build the solution
- Deploy the resultant “Sitecore.Services.Examples.DataProvider.dll” to your Sitecore bin directory
- Deploy the config file “zzzzSitecore.Services.Examples.DataProvider.config” to the App_config folder for example “C:\inetpub\wwwroot\xp902.sc\App_Config\Include\Y.Commerce.Engine”
- Go to your sites “showconfig.asp” and verify that your new data provider has been incorporated into your site. For example, “https://sxa.storefront.com/sitecore/admin/showconfig.aspx”
- Open sitecore content editor and add a new item using the “Commerce Brand Folder” template. You should be able to do this anywhere but for example add it to “/sitecore/content/Brands” (see the banner image for an example)
- When you expand the brands folder, the data provider should retrieve and cache the brands from the commerce engine and show them under the brands folder