Wish List Reference For Sitecore Commerce powered by Commerce Server 8.1

The Sitecore Reference Storefront available on GitHub does not implement wish list capability for Sitecore Commerce powered by Commerce Server (SCpbCS) but does provide it for Sitecore Commerce powered by Microsoft Dynamics (SCpbMD). This means it’s not much work to implement for SCpbCS as all the assets are available, we just need to plug a few gaps. This post is going to run you through how to plug those gaps.

In case you are curious, here is doc that goes through the features available in both the available reference storefront solutions for SCpbCS and SCpbMD – page 9 to 11 of Sitecore.Reference.Storefront.Release.notes.8.1.pdf

One of the reasons for putting this post together is because SCpbCS 8.2 delivers wish list reporting in Experience Analytics which means its important to implement through Sitecore Commerce Connect (SCC). Speaking to a few dev teams delivering Sitecore Commerce projects, they haven’t been aware of the wish list pipelines in SCC. Good news is it pretty easy to implement.

There are a number of SCC pipelines for wish lists. The ones highlighted are the ones available in my commit and you are left with update and delete to implement. With the email and print pipelines you’ll probably use them as is.
commerce.wishLists.addLinesToWishList
commerce.wishLists.createWishList
commerce.wishLists.deleteWishList
commerce.wishLists.emailWishLists
commerce.wishLists.getWishList
commerce.wishLists.getWishLists
commerce.wishLists.updateWishList
commerce.wishLists.updateWishListLines
commerce.wishLists.printWishList
commerce.wishLists.removeWishListLines

If you’re strapped for time jump straight to my GitHub commit to go through the code: https://github.com/kazimnami/Reference-Storefront/commit/7dadeb90b613b41d7aeeae2139fec09e5b9886c1

Sitecore Commerce Connect is an abstract service layer that provides a framework to integration any External Commerce System (ECS). It allows us to track, act, and follow up on customer behavior with the goal being to bring the unique customer engagement features of Sitecore into e-commerce solutions, regardless of the back-end e-commerce system being used. If you need a refresher on SCC refer back to the documentation to understand where it fits into the architecture: http://commercesdn.sitecore.net/SCpbCS81/SitecoreCommerceConnectGuide/en-us/Concepts/c_SitecoreIntegrationArchitecture.html.

The implementation itself uses Commerce Server’s named carts to provide wish lists. Commerce Server’s named cart’s can be used to provide many different features like order templates, re-occurring orders, model store room ordering, etc. Here is a shortened version of my GitHub commit that shows getting all wish lists for user.

var basketManager = CommerceTypeLoader.CreateInstance<ICommerceServerContextManager>().OrderManagementContext.BasketManager;

var requestInformation = GetCartsRequestInformation.Get((ServiceProviderRequest)getWishListsRequest);
var searchableProperties = basketManager.GetSearchableProperties(requestInformation == null || string.IsNullOrWhiteSpace(requestInformation.SearchLanguage) ? "en-us" : requestInformation.SearchLanguage);

var searchClauseFactory = basketManager.GetSearchClauseFactory(searchableProperties, "Basket");
var userIdClause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "SoldToId", csUserId.ToString());
var nameClause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.BeginsWith, "Name", "WishList_");
var searchClause = searchClauseFactory.IntersectClauses(userIdClause, nameClause);

var searchOptions = new SearchOptions();
searchOptions.PropertiesToReturn = string.Format(
    (IFormatProvider)CultureInfo.InvariantCulture,
    "{0},{1}",
    new object[2]{
                (object) "OrderGroupId",
                (object) "SoldToId"
    }
);

var dataSet = basketManager.SearchBaskets(searchClause, searchOptions);

This example gets SQL Server to perform a ‘like’ on the cart name so just ensure that makes sense in your scenario or you can do it in memory i.e. retrieve all baskets and filter them within your C# code.

I also want to point out UserId is saved to the SoldToId column in the OrderTemplateAndBaskets and baskets named ‘Default’ are, as you can imagine, the ones interacted with through the normal ordering journey.

image

The provided commit tries to adhere to the same coding standardsconventions used within the Sitecore Commerce product teams code and show the required code structure to implement wish list functionality through SCC. Use it as a starting point and focus on putting some robust logic around user entered data as you normally would – specifically wish list name.

I hope this post gives you another example of working with SCC and makes your job of implementing wish lists, and similar functionality, significantly easier.