Creating your first plugin

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:

03000013.png

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:

    03000014.png
  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).

    03000015.png
  4. To fix the namespace error, accept the suggestion to change the path to Sitecore.Commerce.Core:

    03000016.png
  5. Once you have fixed the namespace error, fix the other three errors:

    03000017.png
  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:

    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.