allBlogsList

Sitecore Commerce Connect Incremental Product Sync on Marketplace

My module on Incremental Product Sync using Sitecore Commerce Connect was published on sitecore marketplace (Click on marketplace to view the module page)

This blog post will explain the details of Sitecore Commerce Connect Incremental Product sync.

The module gives the ability to sync the products from external commerce system (ECS) based on product’s last modified timestamp in ECS. The sync takes lesser time to run as only the products modified/created after the last product sync was run are updated in sitecore product repository. A sync run history is also saved. This module is an add on module for Sitecore Commerce Connect framework 8.0/8.1.

Installation:

 You can download the package from marketplace.

Install the sitecore package ‘Sitecore Commerce Connect Incremental Prod Sync-1.1.zip’. The package will add the required sitecore items and add config files and the required dll. On successful installation of package, you should see the following contextual button.

The related config file (installed by package) is at the following location:

~/website/app_config/include/incrementalproductsync/IncrementalSync.Core.Pipelines.config

Commerce Connect ECS Pipeline Implementation:

The processor “Sitecore.Commerce. Pipelines.Products.GetExternalCommerceSystemProductList.GetExternalCommerceSystemProductList, Sitecore.Commerce” needs to populate a property with the key ‘ExternalCommerceSystemProductsWithModifiedDateDictionary’ and a value that holds a dictionary of product ids and their modified timestamp in ecs. See the following sample implementation of GetExternalCommerceSystemProductList processor

public override void Process(ServicePipelineArgs args)
{
// GetEcsProductIds is a method that returns product ids from ecs
List productIds = GetEcsProductIds();

// as required by sitecore commerce pipelines to get all product ids.
args.Request.Properties.Add("ExternalCommerceSystemProductIds", productIds.ToArray());

// data structure required for incremental sync. This dictionory holds the product id as the key
// and product's ecs modified date time as the value.
Dictionary<string,> modifiedProductsDatetime = GetProducstModifiedTimeStampDictionary();

// the constant's value is 'ExternalCommerceSystemProductsWithModifiedDateDictionary'.
// This property will be read in the pipeline 'EvaluateProductListUnionToSynchronizeWithTimestamp' 
// to find the products that have changed since last sync.
args.Request.Properties.Add
(Constants.ProductSyncConstants.ExternalCommerceSystemProductsWithModifiedDateDictionary, 
modifiedProductsDatetime);
}

private static List GetEcsProductIds()
{
List productIds  = new List();
// sample code: 1 and 2 are ecs product ids
productIds.Add("1");
productIds.Add("2");

return productIds;
}

private static Dictionary<string,> GetProducstModifiedTimeStampDictionary()
{
Dictionary<string,> modifiedProductsDatetime = new Dictionary<string,>();

// populate the date from ECS database. 
modifiedProductsDatetime.Add("1", DateTime.UtcNow);
modifiedProductsDatetime.Add("2", DateTime.UtcNow.AddDays(-1));

return modifiedProductsDatetime;

}

The constant for the property can be found in the dll IncrementalProductSync.Core. The value of the constant is ‘ExternalCommerceSystemProductsWithModifiedDateDictionary’

Caution:

For the first pass, since there is no record of previous sync run stored, a full product sync will run. Next time the Incremental sync is run, it will look at the previous run timestamp (stored in sitecore core database properties table) and update only the products in sitecore that have been modified in external commerce system after the sync last ran. 

Reporting:

When running the incremental sync from content editor, you will see the status in the progress bar

Also, a csv is created in the sitecore datafolder location. The name of the csv is ‘IncrementalProductSyncHistory.csv’. It has a history of all the incremental sync. See below