Introduction

By default, Sitecore commerce powered by Microsoft Dynamics reference store front fetches inventory levels from the Dynamics AX Channel database, in AX 2012 using the CRT and in AX 7 using the retail server. In other words, the inventory levels shown on the website will be accurate up to the last synchronization of the channel database from the Dynamics AX head office. In particular, accurate up to the last time the “1130 – Product availability” distribution job is run.

Details

The same code is used to show product availability on the product list page (shown above) and on the product details page (shown below). The difference is that on the details page when changing the variant option (color) the inventory will be shown for specific variant id. On the product list page, the code shows “In stock” if there are any variant ids available for the product i.e. the sum of the variants inventory is greater than zero.

product-on-hand-detail

On the product list page, after the first time the product availability is retrieved from Dynamics AX, it is cached and won’t be retrieved again for that specific page of products.

The inventory levels themselves are retrieved for that product in the warehouse assigned to the online store. The Sitecore reference storefront and the underlying framework do support fetching inventory and pricing from another store (Channel Id) by swapping the connection string at runtime. This is useful in scenarios where the user will need to pick a home store. The reference storefront does not currently implement this functionality.

Keeping product availability up to date on the online store

The inventory levels will not be up to date on the online store until the following steps are run in Dynamics AX :-

  1. Run the “P” job to pull online orders into the head office from the channel DB (Retail > periodic > Distribution schedule)
  2. Run the “Synchronize online orders” job to create sales orders (Retail > periodic)
  3. Run the “Product availability” job to calculate product availability (Retail > periodic)
  4. Run the “1130” job to push updates to channel DB (Retail > periodic > Distribution schedule)

The steps above can be scheduled to run every few minutes to enable “near real-time” inventory levels at the online storefront.

Personally, I don’t like that the Microsoft Commerce runtime, on which we rely, requires all these manual steps before the inventory are up to date but unfortunately we are stuck until it is changed.

Customisation options

There are a few options available if the default functionality does not meet your requirements but the most common approach is as follows :-

Create a custom commerce pipeline processor

As with many aspects of Sitecore, you can customize from where the inventory levels are retrieved any which way you choose by implementing a custom pipeline. If you are not a Sitecore person, all a “custom pipeline” is is a custom assembly that contains custom business logic that can pretty much do anything you like.

In order to do this follow these steps :-

  • Create a new commerce pipeline custom assembly for the following processor.
Sitecore.Commerce.Connect.DynamicsRetail.Pipelines.Inventory.GetStockInformation

I will create a detailed post shortly with more information on this topic but the concept is exactly the same as any Sitecore pipeline. There are many articles out there with information on how to accomplish this. A reflecting tool can also be used on the existing pipeline to gain insight on how to do this.

  • Drop the new Sitecore commerce pipeline in the “bin” directory.
  • Replace or update the current pipeline configuration…
<processor type="Sitecore.Commerce.Connect.DynamicsRetail.Pipelines.Inventory.GetStockInformation, Sitecore.Commerce.Connect.DynamicsRetail"> 
<param desc="InventoryCacheTimeout">1</param>
</processor>

…in the config file located here…

[MY SITECORE WEBSITE FOLDER]\App_Config\Include\DynamicsRetail\DynamicsRetail.Connectors.Inventory.config