Sitecore Commerce – Inside the Initialize-CSSite Commandlet

  

In this post, we will take a closer look at the Initialize-CSSite commandlet and how it might behave differently if you are installing a custom site or if you are trying to start from scratch.

The Initialize-CSSite commandlet does a lot stuff. It is actually a convenience commandlet that runs a series of other commandlets for you. The behavior of the commandlet is dependent on the contents of the <CommerceServer> section of your configuration. Typically, this configuration is loaded from the /App_Config/CommerceServer.Core.config file. However, the commandlet will also look in the web.config and app.config files or you can pass in a path with the ConfigFile parameter. Here’s what it does:

  1. Looks in the configuration for a siteName attribute on several different nodes. Normally, this will be on the <application> node, but it will also look at <catalogWebService>, <marketingWebService>, <ordersWebService> and <profilesWebService> nodes if they are present.
  2. Checks to see if a site with the name found in step 1 exists. If it doesn’t, it creates one by calling the New-CSSite commandlet with the site name as a parameter.
  3. Looks at the configuration file to figure out which resources it should create for the site.
    • The catalog and inventory resources are created if the configuration contains a <catalogWebService> or <catalog> node.
    • The profiles resource is created if the configuration contains a <profilesWebService> or <profiles> node.
    • The marketing resource is created if the configuration contains a <marketingWebService> node or if it contains a <caches> node with a <cache name="Discounts"> or <cache name="Advertising"> child node.
    • The orders resource is created if the configuration contains a <ordersWebService> or <orders> node.
  4. Based on the configuration nodes found in step 3, it calls the following commandlets to create the required resources:
    • Add-CSCatalogResource
    • Add-CSInventoryResource
    • Add-CSProfilesResource
    • Add-CSMarketingResource
    • Add-CSOrdersResource
  5. Imports data from XML files in the Data or SitecoreCommerce\Data directory. If the following files are found, the associated commandlet is called.
    • Catalog.xml => Import-CSCatalog
    • Inventory.xml => Import-CSInventory
    • Profiles.xml => Import-CSProfiles
    • Marketing.xml => Import-CSMarketing
    • OrdersConfig.xml => Import-CSOrdersConfig
    • Orders.xml => Import-CSOrders
  6. Looks at the IIS Application Pool to find the user that it is running under and calls the Grant-CSManagementPermissions commandlet with the site name and user name as parameters.

Any custom site that you install will need to have a CommerceServer.Core.config file similar to the one installed by the Sitecore.Reference.Storefront.Powered.by.SitecoreCommerce.10.x.xxx.update package. The Sitecore Commerce Server Connect.10.x.xx.update package also installs a CommerceServer.Core.config.example file that seems to be a bit more full-featured. As a test, I wanted to see what was the minimal file I could use to get through the initialization process. I found that the catalog and profiles resources are required. I suspect this is because those are the remaining legacy components.  So this is the minimal CommerceServer.Core.config file that got me through the initialization:

You will want to use something more complete like the one that comes with the reference storefront before you start adding data. In particular, you should include the configuration for your profile encryption keys.