Creating your first plugin

Current version: 9.2

This example uses a new plugin called Plugin.Sample.Loyalty.

To add your new plugin, use the new template added by the Visual Studio extension:

Add New Project dialog where you can add your new plugin

To create your first plugin:

  1. Give your plugin a namespace and name.

  2. Select the folder to add your plugin to.

    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:

    Visual Studio Solution Explorer showing Plugin Samples
  3. To construct your plugin and add it to your Visual Studio project with a sample Command/Pipeline, click OK.

    The system displays three errors (simple fix-up errors).

    Visual Studio showing system errors displayed in the Error List
  4. To fix the namespace error, accept the suggestion to change the path to Sitecore.Commerce.Core:

    Visual Studio Error List showing suggested fix
  5. Once you have fixed the namespace error, fix the other three errors:

    Remaining errors displayed in the Error List
  6. Follow the suggested fixes for the first two errors. For the third error, fix it by adding the following using to the ConfigureSitecore class:

    RequestResponse
    
    using Sitecore.Framework.Pipelines.DefinitionExtensions;
    

After these minor fixes, your Visual Studio project should build successfully.

The new plugin has an end-to-end sample named Sample that shows an extension from the controller level all the way through running a pipeline. In many cases, you will not want to create a new pipeline, but instead want to extend an existing pipeline to add new processing blocks. You can delete these samples, but we recommend that you keep the samples until you are sure you no longer need them. You can copy and paste from the sample to create new items, such as components, because the sample item contains the necessary structure. Then you can change the naming to your preferred patterns.

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 Sitecore.Commerce.Engine project, right-click the Dependencies node, select Add Reference, and add a reference to your new project.

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

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

Do you have some feedback for us?

If you have suggestions for improving this article,