Sitecore SXA module contains templates, Renderings, Layouts, Placeholder Settings, branch etc. It helps structure the SXA site by scaffolding items required to setup the component.
In this blog post I will walkthrough the steps to create a module manually to have a better understanding and helps specially to debug when there are issues with the existing modules.
Create Module(Part 1)
Navigate to – /sitecore/system/Settings/Feature
Right click Featur folder to create module
Create new module overlay will open.
Provide a Module name – i.e. Custom Image Block
Choose the location where this module to be created.
Select the system areas the module folders to be created
Choose the module should be applied to tenant or site
When module is created should be able to see the folder with the Site Setup Root item
Once the Site Setup Root is created you should be able to see folders with name “Custom Image Block” will be created in Branch, Template, Renderings, Placeholder Settings, Layouts and Media Library or the system areas selected.
Create template required for creating Branch
For creating a branch you will need a template and rendering. Create a template in “Custom Image Block” folder. For now you don’t have to add fields. See blog the fields that were created for component.
Create “Image Block Folder” Template
Create rendering required for creating Branch
Create controller rendering with name “Image Block” in – /sitecore/layout/Renderings/Feature/Wits/Custom Image Block.
For now don’t setup anything in rendering. See blog for the configuration required in rendering-
Navigate to /sitecore/templates/Branches/Feature
Create a new branch. Right click on the folder “Custom Image Block” and insert new branch option
Select the template earlier created-
Branch with name “Image Block” will be created.
Delete $name item in the branch
Rename the Image Block to “Available Image Block Renderings”.
Once a tenant and site are created and/or a theme is manually created you may want to assign a theme to a site. A theme is automatically assigned when during a site creation but what if you want to assign a theme to already created site.
In this blog lets see what does the installation script adds to the SXA site.
Following is the site content structure-
SXA site is a container to the content that will be used as a output of the site. Site contains the settings to select the Site Media Library, Theme Folder and Modules.
2. Home Page
This is the home page of the site. All other pages in the site must be stored under the Home item.
3. Media Folder
Media Folder helps scope the part of media library is available to content editors on the images selection dialog.
You can change the scope by adding or removing the folder in “Virtual” section “Additional Children” field.
Best Practice – Do not put media items directly under the Media folder. Form SXA 1.7 and higher uploading items to media folder in the Site is not allowed.
4. Data Folder
Data Folder is the repository for storing all the data sources. These data sources can be reused across many pages scoped inside the Site. Data folder had component type folder and can be created manually or when the module is installed.
Data for each component can be created manually from the content tree or from experience editor by using the “Associated Content” option. Data folder is used as a source configured in rendering’s Data Source field in a form of query or directly mapped to the component folder.
Best Practice – Clean up unused data sources
Best Practice – Give Site data sources meaningful names
Best Practice – Organize site data sources in folders
Best Practice –Run source field reports to help set the data source context
The presentation folder contains all the presentation related details and settings for the components selected while creating the site.
Presentation folder has list of components based on the modules selected while creating the site.
Presentation folder contains Page and Partial Designs, Layout Service , Available Renderings, Rendering Variants and Styles.
Rendering variant contains list of components on the site and can be customized using Variant Definition and Variant Fields. Also can use template based Variant like Scriban and Template
Settings folder contains site specific configuration. Site Grouping contains the Site Settings like site name, host name, database etc.
Settings also contains the Redirects, HTML snippets and Item Queries. Settings Folder contains options to select the Fav icon, error handling and other SEO related settings.
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>
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-
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-
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-
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.