LibrarySites.Banner

Custom Product Relationships in Sitecore Commerce

Relationships have been around in Commerce Server in some form or another for quite some time. A typical relationship definition might be used to define a product's accessories or related products in other categories; Also called cross-sells and up-sells.

Because of the nature of our Commerce product, and the ability to customize and extend almost every aspect of the platform, you can use these relationships to enable other types of functionality as well. Some other uses might include defining a replacement product in case the current one is out of stock, or associating a soft good like a warranty or related service.

Adding Related Products

By default, using the Merchandising Manager in Sitecore Commerce pb Commerce Server, you can create both a cross-sell and an up-sell without having to do any other configuration:

Add Related Product

But what if you want to include another type of relationship, like the replacement product I describe above? You could certainly use the older (and far less cooler) Catalog Manager desktop application, but you would still need to rely on someone entering the correct relationship name with the correct spelling. Plus, it's likely your merchandisers will want to take advantage of the user experience that the Merchandising Manager UI provides. Instead of reverting to the legacy desktop tool, you can add additional (closed vocabulary) relationship names using the Sitecore Content Editor. 

Customizing Product Relationship Types

Switch to the Core database and navigate to the following path in the Content Editor:

sitecore\client\Sitecore\Applications\Merchandising Manager\ProductDetail\PageSettings\RelationshipsContextMenu

You should see both the CrossSell and UpSell items under the RelationshipsContextMenu item. Right click and select Copy -> Copy To, making a copy of an existing item. Rename the item to suit your specific relationship requirements. In this case, I'm calling mine Replacement to define a replacement product for an out of stock item.

Create new relationship


In the Replacement item details, enter the following:

Title: Provides for localization in the Merchandising Manager UI for selecting relationships
ID: This value is what gets defined in the actual Commerce Server relationship name field
Click: Currently, you need to set the JS click event value. Based on my example it would look like this:

javascript:app.addRelationShip('replacement-relationship', 'Replacement');

Edit relationship item

Saving the item and refreshing the Merchandising Manger UI will reveal a new relationship type, when viewing a product's relationship tab.

ProductDetail.js

There's one more thing you need to do to make it work. In Sitecore Commerce pb Commerce Server version 8.0 there is an issue that requires you to modify the .js file for the Product page; A temporary fix, as this is likely to get addressed in the next release.

Open the following file in your Sitecore web root:

\<instance-name>\Website\sitecore\shell\client\Applications\Merchandising Manager\ProductDetail\ProductDetail.js

Search for the addUpSell function. Add the following function after the addUpSell function:

addRelationShip: function (relationShipName, relationShipLabel) {
   this.itemPickerCatalogFilter = null;
   this.currentRelationshipName = relationShipName;
   this.setDefaultPickerMode();
   this.setItemPickerHeaderTitle(relationShipLabel);
   this.ItemPicker.show();
   this.RelationshipsContextMenu.toggle();
   this.PickerPageSubApp.PickerSearchBox.viewModel.$el.focus();
},

Save the file and clear the browser cache so that the new javascript file is loaded instead of the cached version.

After creating a new product relationship with your new type, it will display in the list of related items on the product Relationships tab:

New related product

Customizing Category Relationship Types

Using relationships at the category level is also supported, but would likely be used for different reasons. A merchandiser might want to associate similar product categories and display links to them on a category landing page, or prominently display a list of special products on a landing page. There are other ways to do this of course, but good examples nonetheless.

Defining a category relationship can be done in almost the same way as a product relationship. Switch to the Core database and navigate to the following path in the Content Editor:

sitecore\client\Sitecore\Applications\Merchandising Manager\Category\PageSettings\RelationshipsGroup

Add a new relationship type as described above, using the same javascript in the Click field as the new product relationship. Editing ProductDetail.js is not required a second time.

Given the flexibility of the platform, it is easy to create additional attributes and relationships to help make a merchandiser's experience even better.