Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

Create Sitecore Commerce Plug-in

December 16, 2019
Create Sitecore Commerce Plug-in
Ketan Garala
Ketan Garala
CTO, Sitecore MVP
Sitecore Commerce Plugins – How to Create Overview

The Commerce Engine is a thin ASP.NET Core application that serves as a host for a group of micro-services that enable commerce fqunctionality. These services are loosely coupled with each other and together, they provide a robust, extensible set of commerce-enabling services.

Services exposed from the engine are exposed as OData/REST based APIs. This enables either direct REST calls to the services, or calls through a generated smart proxy, which examines OData metadata and generates a strongly typed experience for accessing the service.

The initial out-of-the-box Commerce Engine is provided as part of the Sitecore XC SDK. It enables a developer to extend their solution by choosing which plugins are enabled in their solution.

Steps to Create Plugins

The Commerce Engine provided in the SDK is called the Customer.Sample.Solution. You can open the Commerce solution in Visual Studio 2017. The SDK contains the Commerce Engine project itself and some sample plugins that demonstrate a typical extension of the solution.

  1. Give your plugin a namespace and name.

  2. Select the folder to add your plugin to.

  3. In the following example, the plugin is added to the PluginSamples folder in SDK.

    Do not try to add your plugin to a folder outside SDK, as the file paths can conflict with proper builds:

  4. To construct your plugin and add it to your Visual Studio project with a sample Command/Pipeline, click OK.
  5. The system displays three errors (simple fix-up errors).

  6. To fix the namespace error, accept the suggestion to change the path to Commerce.Core:

  7. create-sitecore-commerce-plug-in-5
  8. Once you have fixed the namespace error, fix the other three errors:

  9. create-sitecore-commerce-plug-in-6
  10. Follow the suggested fixes for the first two errors. For the third error, fix it by adding the following using to the ConfigureSitecoreclass:

  11. using Sitecore.Framework.Pipelines.DefinitionExtensions;

    your Visual Studio project should build successfully.

    Once the plugin builds, you must add it to the Sitecore Commerce Engine project as a reference so that the plugin will be pulled in during a build/publish:

    1. Expand the Commerce.Engineproject, right-click the Dependencies node, select Add Reference, and add a reference to your new project.

    2. When the file is saved, it resolves the dependency and loads it when the application is launched.

    3. Once you build the project, press F5to run the solution in debug mode as you did previously. The solution now pulls in your new plugin.

Happy plugin development ????

Contact us for more details ketan@addact.net.