Setup Visual Studio Environment for Commerce Engine Custom Plug-in Development and Debugging

As a solution developer you often need to customize an existing system to provide extended experiences to users. In Sitecore XC, you can create your own customization via Plugins. A Plugin is a combination of pipelines, commands and policies. You can create your own pipeline blocks and attach it to the existing pipelines (will cover this in another post)

The foremost thing to do when you are set out to create your first plugin is setting up your Visual Studio environment. Sitecore XC ships with Commerce Engine SDK which makes the job easier but there are additional things to do before you are ready. This post will focus on setting up Visual Studio and debugging your custom code.

I assume that you have downloaded Sitecore XC 9 package for on premises and completed the setup.

  1. Extract the Sitecore.Commerce.Engine.SDK.2.1.10.zip file

2. Open the Sample plugin solution in Visual Studio

3. Set Sitecore.Commerce.Engine as start up project and choose “Engine” to debug

4. Next step is to update certificate details in config.json. Open \src\Sitecore.Commerce.Engine\wwwroot\config.json file and look for the following in “Appsettings” section

notice that SslPfxPath requires a .pfx file in \src\Sitecore.Commerce.Engine\wwwroot folder but this is missing from SDK (certificates are specific to environment).

5. Generate and update SSL certificate details

You can use the scripts that are shipped with SDK to generate a PFX file for development. Scripts folder is located under

\Sitecore.Commerce.Engine.SDK.2.1.10\scripts

. Run the New-DevelopmentCertificate.ps1. This will generate the localhost.pfx file under wwwroot folder and also install the certificate in user store (Cert:\CurrentUser\Root)
. Run the following powershell command to list the installed certificates and copy the Thumbprint value of the newly installed certificate named “localhost”
Get-ChildItem -Path Cert:\CurrentUser\Root
. Go to config.json file and look for “Thumbprint”
. Replace the existing Thumbprint value with copied value

6. Make sure SQL Server details are correct in Global.json file

\Sitecore.Commerce.Engine.SDK.2.1.10\src\Sitecore.Commerce.Engine\wwwroot\bootstrap\Global.json

7. Stop IIS sites running on port 5000
If you have installed Sitecore XC, you will have CommerceAuthoring site running on port 5000. Stop this site.

8. Run the project

If everything goes well you will see this in console

9. Login to sitecore and launch the business tools

Notice that business tools are now talking to Commerce Engine hosted within Kestrel Web Server.