Welcome! This is my personal blog about Web technologies, software development, open source and other related topics
The ideas and opinions expressed here are solely mine and don't represent those of others, either individuals or companies.The code snippets or references to software products or analogous are to be used without any warranty of any kind. If you enjoy the content, feel free to share it and re-use it as long as you provide a link to the original post.
There are few updates on how the plugins are created in XC 10.
Sitecore Commerce 10 SDK does not include Visual Studio Extension (VSIX) package for creating a plugin project.
Let’s get started and look into the steps to create a new plugin in Sitecore Commerce 10. If you have already set up your commerce development environment, please skip to step 2
Open Powershell in admin mode and navigate to the folder nupkg file is copied and execute following command to install package
dotnet new -i .\Sitecore.Commerce.Plugin.Template.6.0.4.nupkg
Run the dotnet new command and should be able to see Sitecore Commerce Sample Plugin template
4. Create a new Sitecore Commerce Plugin Project
As we have a plugin project template we should be able create a new plugin project.
Execute following command in Powershell. Navigate to the solution src folder-
dotnet new pluginsample -o Sitecore.Commerce.Plugin.SampleTest
New plugin project is created with the project name specified in command.
Include the project in Customer.Sample.Solution and compile.
Notice even though the command has project name “Sitecore.Commerce.Plugin.SampleTest” the actual project is created as “Sitecore.Commerce.Plugin.Sample”. You will have to rename this unfortunately as per your requirement.
Sharding is horizontal partitioning of data in database. It is the process of breaking up large tables into smaller chunks.
Storing rows of the same table in multiple database nodes
In this blog post will see how to split the Commerce Entities table having same structure but store custom entity data in a separate table that helps to split the load that a CommerceEntities table might take if the horizontal partition is not done.
Why partioning of tables is required?
Sitecore Commerce entity data are store in following tables-
CommerceEntities
CommerceEntity
CommerceLists
Any custom entity been created without sharding will store data by default in tables mentioned above.
What if that data increases, there might be a performance hit once the data start expanding over months and years.
Also it wont be good idea to put the multiple custom entity data into a single table. As this might give a performance hit whilst indexing table. So, if you know data might increase over the time it is better to have it saved in a separate table as it can be a boon to high-volume data.
Partitioning data using sharding policy
I assume you know how extend Sitecore Commerce entities. Consider we have a “Organization” entity. Business Tools helps in capturing details of Organization i.e. CRUD operations. When the entity is been saved it has to be saved in different table.
This driven by the sharding policies in Commerce.
Follow these steps to enable sharding of custom entity-
Sharding Policies
The Commerce Engine implements database sharding for Commerce entity and list tables, and provides 2 types of sharding policies. One is for the operation against Commerce entities i.e. EntityShardingPolicy, and other on the Commerce lists i.e. ListShardingPolicy.
Configuration for sharding policy is kept in PlugIn.SQL.Sharding.PolicySet-1.0.0.json file and can be found in data\Environments folder of the Authoring and Shops instance.
As per Sitecore documentation sharding policies has expressions and multiple expression values can be configured based on this the table of the entity is identified to read and perform write operations. This is a bit contrary statement as the table name defined in policies are passed to the stored procedure based on this the data in table is written and read.
Below sharding policy mentions 2 tables-
OrganizationsLists for managing and reading lists of Organizations
OrganizationsEntities for managing and reading Organization entities
To save data in different tables create Entities, Entity and Lists table prefixed with entity name in SitecoreCommerce_SharedEnvironments database
Right click CommerceEntities table select Script Table as option, Create to and then New Query Editor Window. Create script for CommerceEntities table will be generated.
Change the name of table to e.g.:- OrganizationsEntities. Also change the table name to set Default value to EntityVersion and Published fields
Pasrse and check if you are creating a table in correct Database
Execute the script. New table will be created.
Follow same for CommerceEntity table to create OrganizationsEntity and CommerceLists to create OrganizationsLists
So there are 3 tables created so far-
OrganizationsEntities
OrganizationsEntity
OrganizationsLists
Once you have your plugin to perform CRUD operations on Organizations entity you should be able to see the data been inserted in OrganizationEntities, OrganizationLists and OrganizationsEntity table instead of CommerceEntities and there related tables.
Routing constraints lets you restrict how the parameters in the route template are matched. It helps to filter out the input parameter and action method can accept.
For example if the URL Parameter is restricted to have int value, the route engine will match the controller action having integer value in the parameter or restrict.
How Route Constraints are applied-
Using constraint parameter in the MapControllerRoute at the application startup where the endpoints are defined i.e. Inline Constraint
Route attribute at the controller or action method
Route engine when matches the incoming url, it invokes the routing constraint to the the values in the url matches the pattern. In this case which is seperated by : in the above example restricts the value should be int or null.
Quick example on how the routing constraints are defined and used-
Inline Constraint
Inline constraint are added after the URL parameter and sperated by : (colon) with the primitive type and also defines if the parameter can be nullable. Below code see – {id:int?}
The int constraints checks if the parameter value sent is integer and allows to execute the action method by passing the parameter value to the matching method.
The other way to define same if to pass the default values and constraint parameter in the MapControllerRoute
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: " {controller}/{action}/{id?}", new {Controller = "Home", action="Index"}, new {id = new IntRouteConstraint()});
}
);
Constraints in route attribute
You can also define the constraints in route attribute as follows-
[Route("Home/Index/{id:int?}")]
public IActionResult Index(int? id)
{
return View();
}
Here are the list of constraints from the Microsoft doc site, try it yourself-
Constraint
Description
Example
alpha
Matches uppercase or lowercase Latin alphabet characters (a-z, A-Z)
{x:alpha}
bool
Matches a Boolean value.
{x:bool}
datetime
Matches a DateTime value.
{x:datetime}
decimal
Matches a decimal value.
{x:decimal}
double
Matches a 64-bit floating-point value.
{x:double}
float
Matches a 32-bit floating-point value.
{x:float}
guid
Matches a GUID value.
{x:guid}
int
Matches a 32-bit integer value.
{x:int}
length
Matches a string with the specified length or within a specified range of lengths.
Business Tools is extensible using pluggable framework and can extend a UI using Entity Views. Although Business Tools offers a rich set of controls you might want to create your own custom control for the best business experience.
For this you need to first setup the development environment for business tools. Once the environment is setup you should be ready to develop custom control/customize the business tools.
Prerequisites
Instance of Commerce Engine deployed in development environment
NPM configuration to have NPM Packages from Sitecore public feed
Sitecore BizFx SDK relies on NPM packages available on the Sitecore official public feed for NPM packages.
Open Poswershell as Administrator
Execute these 2 commands in powershell
npm config set @speak:registry=https://sitecore.myget.org/F/sc-npm-packages/npm/
npm config set @sitecore:registry=https://sitecore.myget.org/F/sc-npm-packages/npm/
This will add following line to–
C:\Users\[your user]\.npmrc
[Optional] – you may check if this lines are added
Update: Below is applicable for Sitecore Commerce 10.2. Change the SDK version accordingly.Ignore the step mention for Content Hub
Sitecore Experience Commerce 10 has come up with great new features like Dynamic Bundles, Free gift with Purchase promotion and a sample Sitecore DAM to Commerce connector.
Before you start looking into this, it is important to setup the development environment to debug and test the changes you are making to engine.
Main changes I could see compared to previous versions are integration with Content Hub and Configuring the Commerce Engine using environment variables which not only helps for on-premise installation of Commerce Instance but also helps setup the Docker technology where XC solution is running in containers.
In this post I will walk you through on how to setup the development environment. This post assumes you have Sitecore Commerce Engine along with Visual Studio 2019 installed on developer workstation. If Commerce not installed no worries see this post on how to install Sitecore XC 10 step-by-step.
Copy the downloaded SDK Sitecore.Commerce.Engine.SDK.6.0.130.zip on your development folder. e.g: c:\development. Note– there is an update on 19th August where the external dependencies are removed. Download the package again if you have a version before this date.
Extract the commerce package and then extract Sitecore.Commerce.Engine.SDK.6.0.130.zip in your development folder
Step 2 – Setup Visual Studio Solution
Open the Solution, by default this is Customer.Sample.Solution.sln
Ensure Package Source is configured for Commerce- https://sitecore.myget.org/F/sc-commerce-packages/api/v3/index.json
Whilst opening solution login from slpartners.myget.org will be prompted
Create an account on https://slpartner.myget.org/ and login here. You may unload Plugin.Sample.ContentHub project if you dont want to integrate ContentHub and the login should not require. Also note myget account has a trial for 14 days.
Build the Solution. It should restore the package and build successfully.
(optional)Rename the Solution name. In this case I have renamed to Retail.Commerce
(Optional) Create Foundation and Feature projects. Build the solution again.
Step 3- Important – Commerce Engine configuration
Sitecore.Commerce.Engine project should have a config.json file in wwwroot folder. Open this file you will see the placeholders that needs to be filled in.
Instead updating config file, you should update the launchSettings.json and the placeholders in config.json will be updated on launch on commerce engine.
Similarly Global.json you can find this in wwwroot/bootstrap folder of your Sitecore.Commerce.Engine project. Again this file has the Placeholders that will be populated from launchSettings.json,
You need to update mainly following variables in launchSettings.json file for both config and global json. There are other variables apart from listed below, you may need to update those based on your site instance name etc.-
If you are looking for upgrade to Sitecore 10, below are the various options you are able to install Sitecore 10.
Sitecore XP 10
Sitecore Installation Assistant (SIA)
Sitecore Installation Assistant helps guides you through the Sitecore XP Developer Workstation installation. Use this option to review system requirements, install prerequisites and complete the entire installation process. With Sitecore 10 you have a option to also install SXA with SIA.
Sitecore Install Framework (SIF) is a Microsoft PowerShell module that supports local and remote installations of Sitecore Experience Platform.
SIF deploys Web Deploy Packages (WDP) by passing parameters to SIF configuration through a Microsoft PowerShell module and is fully extensible. The Sitecore Experience Platform is designed to be secure-by-default. For developer environments all the required self-signed certificates are created automatically if you do not provide any. In a production environment, you can provide your own certificates In a non-production environment, you can choose to have the module generate the certificates for you.
You must set up SIF before you can install Sitecore Experience Platform
Sitecore Containers support rapid deployment and more efficient solution and team onboarding with modern Docker and Kubernetes technology.
Sitecore Experience Platform 10.0.0 uses Docker Compose as the container orchestrator on developer workstations. Docker Compose is a simple containerdeployment tool that is bundled with Docker for Windows. Sitecore container images can be deployed with other tools but we recommend that you use Docker Compose to deploy the containers that form the Sitecore Experience Platform.
One of the highlights of newly released Sitecore Experience Platform (10.0) is that it brings support to rapid deployment and more efficient solution and team onboarding with modern Docker technology i.e. Sitecore Containers.
To know more about containers here is the official documentation from Sitecore on Containers
Lets get started to create a Sitecore XP 10 development environment using docker.
After installation Restart the machine, this should enable the Hyper-V feature
This should also have Docker running and should see the same in system tray
Switch to Windows containers
Right click on Docker icon and switch to Windows Container. See this link for more details as per guide
Download and Prepare for installation
Download and extract the Sitecore Container Deployment Package from the Sitecore Developer Portal and store it on your local workstation
Login to Sitecore portal before download
Copy and extract SitecoreContainerDeployment 10.0.0 rev. 004346-027.zip for e.g:- C:/SitecoreXPDocker
Navigate to C:/SitecoreXPDocker/ltsc2019/sitecore-xp0
Open .env file, we need to fill in this parameters before starting installation. You can find more details in guide for each option.
Download PowerShell script to initialize (init.ps1) the parameters from docker-examples. Parameter values in .env can be populated manually by individually executing the commands for required for each parameter in guide(see Appendices) but I would recommend to use init.ps1 as this is provided by Sitecore and hence tried and tested.
Folder structure should look like this-
Change parameter values in init.ps1 file.
Change the SitecoreAdminPassword, SqlSaPassword and host entries as per requirement. If you are changing host entries also ensure the same is updated in .env file for CM_HOST and ID_HOST parameters. Lets keep the default values.
Populate .env file using init command
Open PowerShell as a Administrator, navigate to the folder having init.ps1 file.
Execute init.ps1 script. You may have to set the execution rights to current user to execute the script-
1. Switch to sitecorexp10 folder. Open Solr-SingleDeveloper.json file
2. Change the Install Root for SOLR – DefaultValue
"SolrInstallRoot": {
"Type": "String",
"Description": "The file path to install Solr. This config will add the prefix and solr version e.g C:\\Solr becomes C:\\Solr\\[SolrServicePrefix]Solr-8.4.0",
"DefaultValue": "C:\\SOLR"
},
Hope the installation completes without any issues
Post Installation activities
Rebuild the search indexes and the Link database After you install Sitecore Experience Platform, you must rebuild the search indexes and rebuild the Link databases.
To rebuild all the indexes:
On the Sitecore Launchpad, click Control Panel, and in the Indexing section, click Indexing manager.
In the Indexing Manager dialog box, click Select all, and then click Rebuild.
To rebuild the Link databases for the Master and Core databases:
On the Sitecore Launchpad, click Control Panel, and in the Database section, click Rebuild Link Databases.
Select the Master and Core databases and then click Rebuild
Before installing Sitecore Commerce install Sitecore XP 10. See this blog to install Sitecore XP 10 using SIA. Say the XP site name is- sc10.sc.dev.local
Hosting Environment Requirements/ Download and Install following software-
OS – Windows Server 2019/2016 or Windows 10 Pro(64-bit)
Resolution- Check or reset the service account credentials that are created for the app pools as part of deployment. You can find the credentials in installation script with variable name $UserName (CSFndRuntimeUser) and $Password. Try accessing the https://commerceops.sc.com site if there are any other errors.
After installing Sitecore 10 using Sitecore Installation Assistant (see the blog here how to install Sitecore XP 10 usig SIA) you might find the Identity Server not working since it is not able to start the process with command line ‘dotnet .\Sitecore.IdentityServer.Host.dll’
You may see this error in Application logs.
You may also see Sitecore login been not redirected to identity server site instead redirects to XP login page.
To identify the problem first try manually starting the process in powershell. You can find command to start the process in error.
Navigate to the identity server site physical folder and execute this command
dotnet .\Sitecore.IdentityServer.Host.dll
This should tell the solution to the issue i.e. it needs AspNetCore version 2.1.16 to be installed.