Page 15 of 21

Step-by-step – Setup development environment for Sitecore Commerce 9.3 Engine

On a XC installed instance you might want to customize the XC by adding your own Entities, Components, Entity Views etc. In this topic I will describe how to setup your development environment to add your custom plugin.

This topic assumes a Sitecore CMS and Commerce engine version 9.3 are running under IIS. I am using Visual Studio 2019.

Steps to setup-

Step 1- Extract Commerce Engine SDK

  1. Copy the downloaded SDK Sitecore.Commerce.Engine.SDK.5.0.76.zip on your development folder.
  2. If not available you may download Packages for On Premise WDP 2020.01-5.0.145
  3. Extract the commerce package and then extract Sitecore.Commerce.Engine.SDK.5.0.76.zip
Extracted files

Step 2 – Setup Visual Studio Solution

  1. Open the Solution, by default this is Customer.Sample.Solution.sln
  2. Ensure Package Source is configured for Commerce- https://sitecore.myget.org/F/sc-commerce-packages/api/v3/index.json
  3. Build the Solution. It should restore the package and build successfully.
  4. (optional)Rename the Solution name. In this case I have renamed to Retail.Commerce
  5. (Optional) Create a solution folder “Project” and move Sitecore.Commerce.Engine project
  6. (Optional) Rename “Sitecore.Commerce.Engine” project to “Retail.Commerce.Engine”. Re reference AdventureWorks, Habitat and BrainTree projects if required. Adjust/rename namespace in classes.
  7. (Optional) Create Foundation and Feature projects. Build the solution again.
CompileVS

Step 3 – Generate Development Certificate

Generate development certificate using script “New-DevelopmentCertificate”, so the localhost runs on SSL(https)

  1. Open powershell script and navigate to scripts folder.
  2. Execute New-DevelopmentCertificate script
  3. Change the Path($certificateOutputDirectory) if required. Certificate should be copied to \src\Project\Engine\code\wwwroot
generate_certificate
generate_certificate1

Step 4 – Update configuration

  1. Change environment in Engine project/wwwroot/config.json file to HabitatAuthoring
  2. Change “SitecoreIdentityServerUrl”: “https://storefront930.identityserver.local”,
  3. Add the site name in AllowedOrigins in config.json
  4. Open Global.json in  wwwroot/bootstrap folder in Engine project
  5. Update SQL Server, UserName and Password in EntityStoreSqlPolicy
  6. Check the database name
globalconfig1

7. Update Host to your site host name in SitecoreConnectionPolicy

globalconfig2

Note: You may copy the config.json and gloal.json file from Authoring Site hosted in IIS to your project, but to better understand the changes required I have noted the changes. 

Step 5 – Update allowed origins in Identity Site

  1. Open Sitecore.Commerce.IdentityServer.Host.xml file. Should be in /config/production/Sitecore.Commerce.IdentityServer.Host.xml
  2. Navigate to section <CommerceEngineConnectClient><AllowedCorsOrigins>
  3. Add https://localhost:5000 to the

Step 6 – Ready for running the Engine

  1. Set Engine as your Startup Project
  2. Change the debug profile to “Engine” instead of “IIS Express”
  3. In IIS stop Authoring site. i.e. for your default instance it might be CommerceAuthoring_sc930 site
  4. Run the Engine from Visual Studio. This will open the console.
  5. Once the plugins are instantiated, it should listen to 5000 port. At this point you have configured Engine to run/debug from Visual Studio. Any calls from the business tool should be received by engine and console should be able to show the request that’s been received.
RunVSComm1
RunVSComm3

And here we have business tool sending request to engine running on Visual Studio, see GetNavigationView() been called in console-

Bixfx
RunVSComm4

Resharper – My most used shortcuts

Ctrl + T – Find anything in Visual Studio Solution

Fastest way to find files in your visual studio solution. Press this shortcut and start typing the keyword to navigate to your desired file.

Ctrl E + C – Code Cleanup

Re-sharper allows to clean code based on the defined tasks. Configure the tasks for C#, Html , CSS, Javascript etc. and follow the action after pressing this shortcut.

Ctrl R + R – Rename

The Rename refactoring allows you to rename any symbol, including: namespaces, types, methods, parameters, local variables, properties, fields, and events. It automatically finds and corrects all references to the symbol. The Rename refactoring can be invoked directly from the editor and sometimes from other views (Class View, Object Browser).

Ctrl + Alt + D – Todo explorer

Although nobody likes tech debt but there are instances when on an agile projects few tasks are to be pushed back to the future sprint. In such cases a TODO comments are applied. Re-sharper gives a feature to view such TODO items and a best practice its good to fix the TODO items before a production code is ready. Please this shortcut to view all the TODO items in your solution/project

Alt + Enter + Enter

Shortcut helps to rename the file same as the class name. These instances might come after the file (e.g.: .cs) is created and you decide to change the

 

Sitecore Commerce – Product listing page error- The Layout for the requested document was not found

Each Storefront in Sitecore Commerce has its own Storefront settings and Catalog configuration. Whilst configuring multiple environment in a single Commerce instance you might come up with the layout not found error on the Product Listing or Details page.

StorefrontConfiguration

If you see the image above the path is directly been severed from Sitecore Content i.e. a direct navigation is used. To resolve this issue goto- /sitecore/Commerce/Commerce Control Panel/Storefront Settings/Storefronts/Storefront/Catalog Configuration

Uncheck Use Direct Navigation

StorefrontConfiguration_resolve

The product listing and details page should be shown.

StorefrontConfiguration_resolve)product

 

Sitecore 9.3 installation error- Install-SitecoreConfiguration : The ‘Install-SitecoreConfiguration’ command was found in the module ‘SitecoreInstallFramework’, but the module could not be loaded. For more information, run ‘Import-Module SitecoreInstallFramework’.

Whilst installing Sitecore 9.3 received following error-

 

Install-SitecoreConfiguration -Path .\prerequisites.json
Install-SitecoreConfiguration : The 'Install-SitecoreConfiguration' command was found in the module
'SitecoreInstallFramework', but the module could not be loaded. For more information, run 'Import-Module
SitecoreInstallFramework'.
At line:1 char:1
+ Install-SitecoreConfiguration -Path .\prerequisites.json
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Install-SitecoreConfiguration:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

SC93Installation

To resolve this issue, you need to set execution policy to your machine-

Set-ExecutionPolicy -ExecutionPolicy AllSigned

You may also provide a scope to the current powershell session-

Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope Process

This should help resolve issue and any further powershell script execution process depending on what scope you provide the script to run.

References – Set Execution Policy

 

 

 

Step by Step – Create promotions in Sitecore Commerce 9.3

Who don’t like discounts. People eagerly wait for Black Friday or Christmas offers. During festive these are the discounts applied mostly without a promo codes. When its no festive period you may still find the discounts but those asks for promo codes i.e. coupons.

giphypromo

In this article I will walk through how to create and setup the promotions in Sitecore Commerce 9.3  by defining qualifications, benefits and coupons. How the discounts are automatically applied when Public Coupons are set and how to restrict an auto discounts by setting private coupons.

I assume you have installed Sitecore Experience and Commerce 9.3.

See these links more details on Creating and Setting Promotions step by step

Step 1- Promotion dashboard and Promotion Book

To be continued…

 

 

 

 

 

 

 

Sitecore Commerce – Promotion Dashboard and creating Promotion Book in Business Tool

1. Promotion dashboard

Promotion dashboard shows all Promotion Book where all the Promotions are kept. Dashboard allows to add new Promo book.

PromoDashboard

2. Creating a Promo Book

All promotions are organised in a promo book. The list of promotion books on the Promotion dashboard is shown in alphabetical order. Promotion dashboard has options to Add new promotion book. By default Habitat_PromotionBook is created in the Commerce is installed.

To add new promotion book click on Add icon. This should show the popup to add a new promo book.

PromoBookAdd

Promo book with same name cannot be added.

PromoBookAddError1

Promo book name should not exceed 50 characters.

PromoBookAddError2

 

Sitecore commerce – No catalog data available

Sitecore Storefront can have multiple catalogs, but only one catalog can be used to each Storefront.

At times whilst development you might have to switch between the Authoring site and Visual Studio Commerce Engine Solution for debugging. I have seen sometimes the Catalog for the Storefront is reset during the switch which results in error – No catalog data available.

This message is shown on the menu as seen in the screenshot-

ErrorNoCatalogDataAvailable

ErrorNoCatalogDataAvailable2

Solution-

Login to Sitecore Client and follow these steps-

  1. Navigate to following location in Content Editor-  /sitecore/content/Sitecore/Storefront/Home/CatalogsSelectCatalog
  2. If none of the Catalog is selected, please select the Catalog and Save. In this case Habitat_Master
  3. Should now display the menu as the Catalog details are now setupErrorNoCatalogDataAvailable1

You also might need to consider checking Catalog Configuration here – /sitecore/content/Sitecore/Storefront/Settings/Commerce/Catalog Configuration

Setup the Catalog and Start Navigation Category

CatalogConfiguration

 

Hope this helps.

 

 

Sitecore Commerce environments- configure and access environment policy

Environments in Sitecore XC are used to control the configuration policies that defines behavior. Define a Commerce environment in the environment configuration JSON file. JSON file contains information specific to Commerce Engine policies that needs to be implemented for specific environment for example Habitat Authoring.

In this article will show how to configure the policy in a specific environment JSON file and access the policy that affects the behavior based on the settings.

First check the default environment. Open Sitecore.Commerce.Engine.Connect.config and see

<defaultEnvironment>HabitatAuthoring</defaultEnvironment>

In this case will add a setting to include Sitecore Clinet Url in enviornment-

Open Comerce Authoring – wwwroot\data\Environments folder

Since the default environment is HabitatAuthoring, you should update PlugIn.Habitat.CommerceAuthoring-1.0.0.json file-

{
"$type": "Sample.Commerce.Plugin.Management.Policies.SitecoreCmsServerPolicy, Sample.Commerce.Plugin.Management",
"ServerHostName": "https://mystorefront.local/"
},

Restart IIS. Hope you already know how to run the Commerce Ops script using postman.

Open Postman, run the GetToken and in SitecoreCommerce_DevOps

run Bootstrap Sitecore Commerce.

This should sync the environment related changes.

Assuming you have a plugin. Create a policy in  Sample.Commerce.Plugin.Management.Policies namespace with the class SitecoreCmsServerPolicy inherited from Policy as below-

using Sitecore.Commerce.Core;

namespace Sample.Commerce.Plugin.Management.Policies
{

public class SitecoreCmsServerPolicy: Policy
{
public string ServerHostName { get; set; }
}
}

You can use the environment configurations by getting the policy as folloes-

var cmsSitecoreServerPolicy = context.GetPolicy<SitecoreCmsServerPolicy>();

cmsSitecoreServerPolicy.ServerHostName;

You should now get the value “https://mystorefront.local/” when ServerHostName is accessed.

You may update these environment files- PlugIn.Habitat.CommerceShops-1.0.0.json for shops environment

Hope this helps.

 

Reference- Commerce Engine environments

 

 

 

 

 

 

Some useful PowerShell commands

Check version of PowerShell with following command-

get-host | select-object version

 

Set unrestricted execution to current user

Set-ExecutionPolicy -Scope CurrentUser Unrestricted

This should also the following error when trying to execute a script – cannot be loaded because running scripts is disabled on this system.

 

How to install and switch between multiple versions of Sitecore Installation Framework.

Installation – Sandeep Pote

To run the multiple versions of Sitecore Installation Framework (SIF) first check the installed versions with following command-

Register the repository command followed by SIF List available command-

Register-PSRepository -Name SitecoreGallery -SourceLocation https://sitecore.myget.org/F/sc-powershell/api/v2

Get-Module SitecoreInstallFramework –ListAvailable

This should list the all the installed version of SIF

sifv1

In this case it shows 2.1.0 and 1.2.1 installed.

To list the version version that is currently in use, execute following command-

Get-Command -Module SitecoreInstallFramework | Select-Object -Property name, version

sifv2

Currently it shows v1.2.1 is active, to switch to the latest version i.e. 2.1.0 or any other version, run the following command-

Remove-Module -Name SitecoreInstallFramework
Import-Module -Name SitecoreInstallFramework -RequiredVersion 2.1.0

Now this should switch to the version 2.1.0

Hope this helps.