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.
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.
Sitecore Commerce indexes Catalogs, Categories and SellableItems to help search items in Business tools. The settings for the Search can be found in PlugIn.Search.PolicySet-1.0.0.json
These indexes has a search scope, for searching catalog and related items by default the scope is “xc910CatalogItemsScope”
So in SOLR indexed items related to catalogs are kept in core – “xc910CatalogItemsScope”
By default Sitecore will index only Habitat Environment in Sitecore Commerce 9.1. If you want to index your custom environment or AdventureWorks environment, follow these steps-
Open Sitecore.Commerce.Engine.Connectors.Index.Common.config file. This should be in CM Y.Commerce.Engine folder
In this instance for Adventureworks add “AdventureWorksAuthoring” in Environemnts element for Master Index and “AdventureWorksShops” for Web Index
Open Postman and Run – Full Index Minion Catalog Items
Check if the items are indexed correctly in SOLR.
Search the same keyword in Business tool for AdeventureWorks environment
In my last post, I have described the steps to set up the Sitecore Commerce development environment. In this post, I will describe how to create a custom plugin in Sitecore Commerce. I was working on version 9.3 but these steps should work with all versions of 9 series.
Sitecore Commerce provides an extensible framework which can be extended using plugins. A plugin is an independently publishable extension to the Sitecore Commerce Engine. Generally, you will find the following contained in a plugin and are used to extend the platform.
Entities
Components
Entity Views
Pipeline
Policies etc.
You can extend the platform or add more features using the plugins. Let’s get started and look into the steps to create a new plugin in Sitecore Commerce 9.3. If you have already set up your commerce development environment, please skip to step 2
Step 2 – Install Visual Studio Extension for creating plugin
Go to solution root folder or SDK folder and run the Sitecore.Commerce.Plugin.vsix file. Close the Visual Studio solution if open.
This should install extension on selected Visual Studio Version
Step 3 – Create a plugin
Open your solution. Create a Feature solution folder, just to follow Helix best practice. Right click solution folder to create a new project
Search Sitecore.Commerce.Plugin. Select project type and click next.
Give the project name, location and select .Net Framework 4.7.1. Create a Project.
Sample Folder and Files for Commands, Components, Controller etc shall be added.
Update the Sitecore Commerce Core from 5.0.0 to 5.0.4
4. Build the project. There shouldn’t be any reason the build should fail.
Step 4 – Reference project and run engine
Add Plugin project reference to your Commerce.Engine Project
Run the Engine. You should be able to see the newly created plugin is now registered in Engine.
This should allow to start customizing commerce and truly use plug-gable and extendable feature of Sitecore Commerce.
We intentionally didn’t add any code to this plugin to keep this simple. In the next blog, we will cover the anatomy of the newly created plugin and show how to inject this plugin into Commerce Pipelines and execute some custom code.
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
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-
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-
Solution-
Login to Sitecore Client and follow these steps-
Navigate to following location in Content Editor- /sitecore/content/Sitecore/Storefront/Home/Catalogs
If none of the Catalog is selected, please select the Catalog and Save. In this case Habitat_Master
Should now display the menu as the Catalog details are now setup
You also might need to consider checking Catalog Configuration here – /sitecore/content/Sitecore/Storefront/Settings/Commerce/Catalog Configuration