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.
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.
Are you wondering why this error occurred while registering user?
You may come across this error when the engine is trying to create a customer in Commerce and the domain you have created for Storefront is not available in Commerce. The customer in commerce are mapped to the domain and if the domain is not found or matched with what is configured in Storefront this error will come.
So how to resolve this error-
Lets say your Storefront is mapped to use the default environment i.e. HabitatShops.
Follow steps below to make this work-
Open PlugIn.Habitat.CommerceAuthoring-1.0.0.json and find the CustomerPropertiesPolicy
You may see the list of Domains default been Storefront, extranet and CommerceUsers
Add the domain you have configured in your storefront in this list e.g.:- HabitatStorefront
Add the same domain to PlugIn.Habitat.CommerceShops-1.0.0.json
Ensure the domain is created and mapped in the Storefront correctly
Bootstrap Habitat Environment using Postman and now you should see the domain in the list whilst creating a customer
You should now able to see the domain in the list whilst creating a customer in business tool
Should also allow to create a customer with the new domain-
In my previous post we saw the first step to create a new plugin by adding a new plugin project to the solution, restoring the correct binaries and reference new plugin to the Engine project.
In this post I will share what comes with the Plugin project template.
Sitecore Commerce Plugin project template creates folders and classes which helps to quick start creating a plugin, lets see what are these files –
1. Commands
To my understanding command is unit of work to perform set of actions. Commands allows to execute a pipeline and blocks within a transaction scope. Create a custom command by inheriting from CommerceCommand class. Use PerformTransaction method to run a pipeline in a transaction scope.
2. Components –
If you want to extend existing or custom entities, use component. Component has attributes that support entities.
3. Controllers –
Controllers expose commerce functionality implemented in plugins. They are the api endpoints. Sitecore Commerce has various Controller type- Entity, Api, Devops and Command. Create your own controllers by inheriting from CommerceController
4. Entities-
They are the persistable unit and represent the business concept. Inherited from the CommerceEntity they has a unique identifier that helps to retrieve the entity by using a Entity controller type.
5. Models –
They are the POCO classes that are reusable in entities and components. Can be used to present data as part of command response .
6. Pipelines – They do the heavy lifting in plugin by making it possible to define the extensible behavior. Create your own pipeline and add blocks you want to execute to implement your business logic. Blocks within pipelines execute in a sequence they are registered.
7. Policies –
Policies defines behavior for the functionality provided by the plugin. Its is recommended to not extend or inherit out-of-box plugins instead create your own. Plugins can be changed or created new by updating the JSON files provided in environment folder of the various roles site.
ConfigureSitecore –
ConfigureSitecore class helps to register the pipeline and block definitions that a plugin defines. You can create a new plugin and AddPipeline or extend the existing pipeline by adding a block After or Before any existing blocks. ConfigureSitecore class registers pipelines every time engine loads. You can also register commands or register your custom class in this class.
ConfigureServiceApiBlock –
This registers customer entities, components and controller action with ODATA model. It allows to these elements to be used when a REST API call is made and available when generating a proxy.
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.
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
Copy the downloaded SDK Sitecore.Commerce.Engine.SDK.5.0.76.zip on your development folder.
Extract the commerce package and then extract Sitecore.Commerce.Engine.SDK.5.0.76.zip
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
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 a solution folder “Project” and move Sitecore.Commerce.Engine project
(Optional) Rename “Sitecore.Commerce.Engine” project to “Retail.Commerce.Engine”. Re reference AdventureWorks, Habitat and BrainTree projects if required. Adjust/rename namespace in classes.
(Optional) Create Foundation and Feature projects. Build the solution again.
Step 3 – Generate Development Certificate
Generate development certificate using script “New-DevelopmentCertificate”, so the localhost runs on SSL(https)
Open powershell script and navigate to scripts folder.
Execute New-DevelopmentCertificate script
Change the Path($certificateOutputDirectory) if required. Certificate should be copied to \src\Project\Engine\code\wwwroot
Step 4 – Update configuration
Change environment in Engine project/wwwroot/config.json file to HabitatAuthoring
Add the site name in AllowedOrigins in config.json
Open Global.json in wwwroot/bootstrap folder in Engine project
Update SQL Server, UserName and Password in EntityStoreSqlPolicy
Check the database name
7. Update Host to your site host name in SitecoreConnectionPolicy
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
Open Sitecore.Commerce.IdentityServer.Host.xml file. Should be in /config/production/Sitecore.Commerce.IdentityServer.Host.xml
Navigate to section <CommerceEngineConnectClient><AllowedCorsOrigins>
Add https://localhost:5000 to the
Step 6 – Ready for running the Engine
Set Engine as your Startup Project
Change the debug profile to “Engine” instead of “IIS Express”
In IIS stop Authoring site. i.e. for your default instance it might be CommerceAuthoring_sc930 site
Run the Engine from Visual Studio. This will open the console.
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.
And here we have business tool sending request to engine running on Visual Studio, see GetNavigationView() been called in console-
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.
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
The product listing and details page should be shown.
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-
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.
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