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.
Sitecore supports multitenancy, which means you can have multiple sites running on a single Sitecore instance.
Tenant folder is just a container to hold multiple tenants you may have as a part of site structure. Inherited from _Base Tenant Folder. You may create a tenant folder to hold the multiple tenants of a Company.
A folder with provide tenant folder name is create here – /sitecore/templates/Project/<Tenant Folder Name>
Tenant is a top-level container for the Sites underneath. Site in same tenant are related, that means they are able to share data and layouts. Creation of tenants comes with optional modules.
Voluntarily contributing your time, energy and skills to the community and help customers succeed and be a part of their growth is all that matters. I believe going above and beyond to achieve expertise in whatever you are doing and giving back to community however small it may be is the key to grow together and when these efforts are recognized it inspires the community to continue their good work.
Happy to share that I have been recognized as 2021 Sitecore MVP.
Sitecore recognizes professionals who deliver outstanding customer experiences through shared expertise on Sitecore’s products, the 2021 MVP program draws from a community of 12,000 certified developers and over 20,000 active participants. This year’s 284 MVPs contributed invaluable knowledge to the community in 2020 and demonstrated true mastery of the Sitecore platform to support partners, customers and prospects.
Sitecore Commerce supports integration to the third-part system and customization and extension to the OOTB entities. This can be achieved by custom plugins.
If you are migrating your code from XC 9.x version to XC 10 you will have to update the code to newest API’s provided with XC. Following is the list of breaking changes if migrating from older versions or good to know if you are starting with the new XC 10 solution.
Wrappers to PipelineBlock
Commerce Engine uses pipeline framework to support extensibility. Pipelines act as a containers for business logic. Commerce pipeline consists of a block which has a detailed business logic.
With Sitecore 10 PipelineBlock are now wrapped with AsyncPipeline and SyncPipeline. So if you have your code using PipelineBlock it should be using Run method to execute the block you may have injected to pipeline.
AsyncPipelineBlock
If block needs to be executed Asynchronously use AsyncPipelineBlock. Also the method name changes to RunAsync()
SyncPipelineBlock
If block needs to be executed Synchronously use SyncPipelineBlock. The method name used to execute block is Run()
ConfigureServiceApiBlock also now uses SyncPipelineBlock
2. IPipeline RunAsync() method
IPipeline interface method is changed from Run to RunAsync() which now makes sense as the method is asynchronous operation.
So where are the changes you might need to make, some of the pipelines that is used frequently and need change are listed below-
IFindEntityPipeline
IFindEntitiesInListPipeline
IFindEntitiesPipeline
IPersistEntityPipeline
Any custom pipeline and list goes on…
Api Controller
Commerce api controller exposes the endpoint to communicate from FE or Commerce Connect to Commerce Engine. You can create custom endpoint and the api controller inherited from class CommerceController.
With XC 10.x the class file to inherit for same is CommerceODataController
This is a Part-2 of customizing Sitecore Commerce Business Tools. To see how to setup the environment for customization before you could start creating a custom component see Part-1
Often you have seen entity details are shown in Flat view i.e. horizontally, fields and there values are displayed. If you have too many fields to display flat view doesn’t seem to be user friendly. In this case the best way to display such details will a vertical view.
This post assumes Instance of Commerce Engine deployed in development environment and a custom entity is created. This is just a example on how to extend Business Tools using Angular which shows the flexibility of Business Tools in terms of cusotmization.
I have a entity named Organization and captures details for same which has quite a few properties as seen in below screen-
There are around 10 fields in the details section of the entity. These fields are squeezed and also doesn’t look user friendly. This would go more ugly if there are more fields added in the entity.
Sitecore Entity View default UIHint is Flat where a single row is displayed in a form of table.
This would look better if it is displayed in Vertical View or Form View i.e. each field in a different row.
Lets see how this can be done using BizFx SDK and the development environment we have created in this post – <<ENTER SETUP DEV BUSINESS TOOL ENVIRONMENT LINK HERE>>
Sitecore business tools already have Flat and Table View. Flat been default. Lets create a new view called as Vertical View.
Open the folder where the SDK zip file was extracted and navigate to src/app/components/views folder
View folder should look like this-
Copy paste and rename following files-
Copy and Rename sc-bizfx-flatview.component.css to sc-bizfx-verticalview.component.css
Copy and Rename sc-bizfx-flatview.component.html to sc-bizfx-verticalview.component.html
Copy and Rename sc-bizfx-flatview.component.ts to sc-bizfx-verticalview.component.ts
Open sc-bizfx-verticalview.component.html. Change the table to display the property name and value-
That’s all changes required to have a custom component in Business Tools.
Next open PowerShell and build the changes made and run the Business Tools site
ng serve
The site should now listen to 4200 port.
Now lets create/update a entity view with a Vertical view UIHint. I already have entity with the Flat view. I will change the UIHint to “Vertical” to display the properties and there values vertically.
Build and deploy engine changes to Authoring site. (Not covered in this blog)
Using Flat view either squeezes the table or a horizontal scroll which is not user friendly. With the Verticalview Organization details are now shown vertical with the Property Names and Values in different rows.
This view is more readable for user specially with the long text in Address.
Easy to implement and test on development environment you can build more complex controls with the same approach
Next post will see how to deploy these changes to production.
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.-