The Sitecore Commerce SDK comes with a number of sample plugins which serve varying purposes, including upgrading/migrating data from Sitecore Commerce 8.2.1, providing Habitat and AdventureWorks sample data for testing and getting familiar with the Commerce Engine’s services, and a working Braintree payment integration.
In this article, we will look at the steps required to decouple the sample projects from the solution and resolve the dependencies that the Commerce Engine project has on them, to provide a clean starting point for customising and extending your project’s instance of the Commerce Engine.
Note: We will leave the Braintree plugin in the solution so we can still checkout in the storefront. We will also leave the habitat environment configuration files, which can be updated to the custom environment names for your solution.
We will go into detail below, but let’s take a quick look at what’s required at a high level:-
- Add dependency references to the Commerce Engine
- Add necessary pipeline configurations to the Commerce Engine
- Remove policies for sample projects from the environment configuration files and policy sets
- Remove sample environment configurations and policies from the Commerce Engine
- Remove sample projects from the solution
- Test the Commerce Engine
Add Dependency References to the Commerce Engine
The following dependencies will need to be added to the Commerce Engine for the project to build once the sample projects have been removed:-
- Sitecore.Commerce.Plugin.Coupons
- Sitecore.Commerce.Plugin.Journaling
- Sitecore.Commerce.Plugin.SQL
- Sitecore.Commerce.Plugin.Tax
Note: For versioning, confirm with the other plugin references.
Add Necessary Pipeline Configurations to the Commerce Engine
The Commerce Engine is missing a few pipeline configurations that hook up some of the cart functionality. To resolve this, perform the following steps:
- Copy the ServiceCollectionExtensions class from the Plugin.Sample.AdventureWorks project into the Commerce Engine project at Pipelines > Blocks.
- Rename the namespace to Sitecore.Commerce.Engine.
- Copy the ConfigureSitecore class from the Plugin.Sample.AdventureWorks project into the Commerce Engine project.
- Rename the namespace to Sitecore.Commerce.Engine.
- Replace the ConfigureServices method with the following:
public void ConfigureServices(IServiceCollection services) { var assembly = Assembly.GetExecutingAssembly(); services.RegisterAllPipelineBlocks(assembly); services.ConfigureCartPipelines(); }
- Resolve ConfigureCartPipelines by adding in the following to the class:
using Sitecore.Commerce.Engine.Pipelines.Blocks;
Remove Sample Environment Configurations and Policies from the Commerce Engine
Highlighted in red are the properties, policies, and environment configuration files to be removed from the solution.
- Global.json
- EnvironmentList
- “AdventureWorksShops”
- “AdventureWorksAuthoring”
- Plugin.Sample.Upgrade.MigrationPolicy
- Plugin.Sample.Upgrade.MigrationSqlPolicy
- EnvironmentList
- PlugIn.AdventureWorks.CommerceAuthoring-1.0.0.json
- PlugIn.AdventureWorks.CommerceMinions-1.0.0.json
- PlugIn.AdventureWorks.CommerceShops-1.0.0.json
- PlugIn.Habitat.CommerceAuthoring-1.0.0.json
- Sitecore.Commerce.Core.EnvironmentInitializationPolicy
- “Environment.Habitat.DefaultRelationships-1.0”
- “Environment.Habitat.SellableItems-1.0”
- “Environment.Habitat.Pricing-1.0”
- “Environment.Habitat.Promotions-1.0”
- “Environment.Habitat.Catalog-1.0”
- Plugin.Sample.Customers.CsMigration.ProfilesSqlPolicy
- Plugin.Sample.Customers.CsMigration.ProfilePropertiesMappingPolicy
- Sitecore.Commerce.Core.EnvironmentInitializationPolicy
Remove Sample Projects from the Solution
We can now remove the following projects from the solution:-
- Plugin.Sample.AdventureWorks
- Plugin.Sample.Customers.CsMigration
- Plugin.Sample.Habitat
- Plugin.Sample.Upgrade
The solution should now resemble the image below.
Test the Commerce Engine
To verify the solution:-
- Run the Commerce Engine project locally.
- Run the Bootstrap request, either via postman or browser.
- Run the CleanEnvironment request.
- Run the InitializeEnvironment request.