Setting up a new Sitecore Experience Commerce Environment


Sitecore Experience Commerce 9 comes with two default environments - Habitat and AdventureWorks. In this post, I will describe how you can safely remove these environments, create new environments and how to remove the sample projects from Sitecore Commerce Engine SDK.

When you are starting on a new project, the Sitecore Commerce Engine SDK gives a good headstart with all the sample projects. Eventually, you will need to remove these sample projects and keep only the ones that are needed for the project.

Step # 1

1. Create an envionment file that can be boostrapped - Suppose your new environment name is sandbox, you should create a new environment file to load it into the commerce database on bootstrap. Copy the PlugIn.Habitat.CommerceAuthoring-1.0.0.json and rename it to PlugIn.Sandbox.CommerceAuthoring-1.0.0.json

Open the newly created json, modify the following:

  • ArtifactStoreId - new guid
  • Id - Entity-CommerceEnvironment-SandboxAuthoring
  • Name - SandboxAuthoring

Now, repeat the same step for CommerceShops and CommerceMinions jsons for habitat. The only thing that ties up all three jsons together is the artifact store id. It should be same on all three jsons.

 

Step # 2

2. Check the json for completeness, remove any policy that you don't want. Also add any new policy that you are creating for the project in these environment jsons.

 

Step # 3

3. Update EnvironmentInitializationPolicy

By default it will have habitat policies, remove and add your custom policies here. Do keep in mind that there are some relationships policies that are needed here.These values will be used in the initialize environment process. (Step 4).

 

Step # 4

4. Initialize Environment Pipeline

Look at the InitializeCatalogBlock.cs under plugin.sample.habitat project. It is called during the initialize pipeline of the environment. If you want to add some default catalog structure, or promos or inventory sets, you can add custom steps using block and add the block in the ConfigureSitecore of your plugin. Again refer to Sample Habitat plugin and create a new plugin to handle all initialization of your new environment. It will give you an idea on where to start.

 

Step # 5

5. Default Behavior on CartTotal

In the class ServiceCollectionExtensions under AdventureWorks plugin, you will see that ICalculateCartLinesPipeline, ICalculateCartPipeline and IAddPaymentsPipeline have some blocks added/ if we remove this plugin from the solution, your carttotals will be 0 always and some other issues arise on getCartLine. So, add these configuration in the ConfigureSitecore of your new plugin because we will remove the sample plugins from solution.

 

Step # 6

6. Plugin.Sample.Customers.CsMigration

When you remove this plugin and bootstrap, you will see that when you bootstrap, you get an error that json is invalid. That is because this class is referenced in the Environment Json that we just created. Remove all configurations from the environment jsons that refer to Plugin.Sample.Customers.CsMigration. 

Step # 7

7. Change configs, Bootstrap and Initialize

Open Global.json, add the new environments to the list of existing environments (HabitatAuthoring, HabitatShops, etc) Run the engine, open postman, Bootstrap and Initialize the environment you just created. Clean the environments - Habitat and AdventureWorks 

 

Step # 8

8. Remove dependencies from Sitecore.Commerce.Engine project

Remove AdventureWorks, Habitat and Customers sample projects from the reference.That is all you have to do to remove the sample environments and plugins.

 

Next step is to make some configuration changes in Sitecore. 

 

Step # 9

9. After the commerce engine changes are done, you will see that when you re-index, you get an error. That is because, OOTB, Sitecore has a indexconfguration file that looks up "HabitatAuthoring" shop.

Add the following patch file and change your shop name from habitatAuthoring to SandboxAuthoring

  <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:search="http://www.sitecore.net/xmlconfig/search/" xmlns:role="http://www.sitecore.net/xmlconfig/role/"> <sitecore role:require="Standalone or ContentDelivery or ContentManagement" search:require="solr"> <contentsearch> <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch"> <indexes hint="list:AddIndex"> <index role:require="Standalone or ContentManagement" id="sitecore_master_index"> <locations hint="list:AddCrawler"> <crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.SellableItemsCrawler, Sitecore.Commerce.Engine.Connect"> <itemstotake>100</itemstotake> <listname>SellableItems</listname> <indexlistname>SellableItemsIndex</indexlistname> <environments hint="list"> <environment>SandboxDPAuthoring</environment> </environments> <database>master</database> </crawler> <crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.CategoriesCrawler, Sitecore.Commerce.Engine.Connect"> <itemstotake>100</itemstotake> <listname>Categories</listname> <indexlistname>CategoriesIndex</indexlistname> <environments hint="list"> <environment>SandboxDPAuthoring</environment> </environments> <database>master</database> </crawler> <crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.CatalogsCrawler, Sitecore.Commerce.Engine.Connect"> <itemstotake>100</itemstotake> <listname>Catalogs</listname> <indexlistname>CatalogsIndex</indexlistname> <environments hint="list"> <environment>SandboxDPAuthoring</environment> </environments> <database>master</database> </crawler> </locations> </index> <index id="sitecore_web_index"> <strategies hint="list:AddStrategy"> <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/sellableItemsIntervalAsynchronousStrategyWeb"></strategy> <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/categoriesIntervalAsynchronousStrategyWeb"></strategy> <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/catalogsIntervalAsynchronousStrategyWeb"></strategy> </strategies> <locations hint="list:AddCrawler"> <crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.SellableItemsCrawler, Sitecore.Commerce.Engine.Connect"> <itemstotake>100</itemstotake> <listname>SellableItems</listname> <indexlistname>SellableItemsIndex</indexlistname> <environments hint="list"> <environment>SandboxDPAuthoring</environment> </environments> <database>web</database> </crawler> <crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.CategoriesCrawler, Sitecore.Commerce.Engine.Connect"> <itemstotake>100</itemstotake> <listname>Categories</listname> <indexlistname>CategoriesIndex</indexlistname> <environments hint="list"> <environment>SandboxDPAuthoring</environment> </environments> <database>web</database> </crawler> <crawler type="Sitecore.Commerce.Engine.Connect.Search.Crawlers.CatalogsCrawler, Sitecore.Commerce.Engine.Connect"> <itemstotake>100</itemstotake> <listname>Catalogs</listname> <indexlistname>CatalogsIndex</indexlistname> <environments hint="list"> <environment>SandboxDPAuthoring</environment> </environments> <database>web</database> </crawler> </locations> </index> </indexes> </configuration> </contentsearch> </sitecore> </configuration>
 

Step # 10

10. Change the defaultEnvironment in the config to point to new environment SandBoxAuthoring (using a patch file)

 

 

Keep in mind that i changed the shopName as well, this is not created in Commerce, Commerce Engine uses Items API to query Commerce Control Panel in Sitecore and there should be an item under storefront that matches the name of the defaultShopName attribute above. Just duplicate CommerceEngineDefaultStorefront and rename it to Sandbox.

 

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/"> <sitecore role:require="Standalone or ContentManagement"> <commerceengineconfiguration> <defaultenvironment>SandboxAuthoring</defaultenvironment> <defaultshopname>Sandbox</defaultshopname> </commerceengineconfiguration> </sitecore> </configuration>

SEARCH ARTICLES