Monday, February 19, 2018

Sitecore Experience Commerce - Extending an inventory item with a plugin

Out of the box, inventory items (otherwise known as a SellableItem) in Sitecore's Experience Commerce provide fields which will cover most eCommerce business requirements. However when a requirement comes up to add additional custom fields, you will need to create a Plugin.

The developer's guide for Experience Commerce 9.0 has a section on creating your first plugin, however sometimes it's easier to understand when given a working example.

Experience Commerce - creating a plugin
Sitecore provides a guide for How to extend Catalog system entities schema in Sitecore Experience Commerce 9.0. I will expand on this to show how to get this example working in your Experience Commerce instance.
  1. Download the example project, which is available on the page above. This is the plugin which adds custom fields to inventory items.
  2. Rename this plugin to fit in with your organisation's naming conventions and modify to the code to meet your requirements. Effectively you replace all instances of Note or Notes and modify the two fields the example adds to meet your requirements (in my case I needed 4 fields).
  3. Extract the commerce SDK to a suitable location (at the time of writing, the version is: Sitecore.Commerce.Engine.SDK.2.0.1922). 
  4. Install the Sitecore.Commerce.Plugin.vsix Visual Studio plugin contained in this folder.
  5. Inside this folder is the Customer.Sample.Solution solution. This contains the commerce engine and a number of sample plugins.
  6. Move your customized Plugin.Sample.Notes project into the src folder (Sitecore.Commerce.Engine.SDK.2.0.1922\src) and then add this project to the solution.
  7. Plugin referenced in the commerce engine
  8. Add this project as a reference to the Sitecore.Commerce.Engine project.
  9. In the Sitecore.Commerce.Engine project, update the config.json values to match that of your commerce sites (authoring, minions, ops and shops). The key values to update are that of: Thumbprint and EnvironmentName.
  10. Ensure the solution builds correctly, you may need the Sitecore Commerce Nugget package source configured:
  11. Publish the Sitecore.Commerce.Engine project to your 4 commerce sites (authoring, minions, ops and shops). Of course you should back these up before publishing.
  12. Load up the content editor of your Sitecore instance and click Update Data Templates on the commerce ribbon. 
  13. Sitecore Experience Commerce - Update Data Templates
  14. Now if you open up the inventory manager in the Commerce UI, you are able to view and edit your new custom fields.
Experience Commerce - Extended catalog item
From my experience, any errors during this process often relate to the SLL certificates and their thumbprints.

No comments:

Post a Comment