Tutorial: Indexing profit margin data for use in dynamic product recommendation

(Developer) In this tutorial, you customize WebSphere Commerce search to use specific search conditions to dynamically recommend products to customers based on the profit margin for the products. Profit margin of a product is how much profit in percentage the store earns for every dollar of sale. This tutorial uses the following formula to calculate the profit margin.

In WebSphere Commerce we can have offer prices for products in different currencies and have a different range price. This tutorial guides you to use the base offer price (the price that customers pay for the product when they buy one unit of the product) in US dollar to calculate the profit margin. We can use the other currency to calculate the profit margin as well. Cost prices are not stored by default in WebSphere Commerce. We must either create a separate price list in the Management Center Catalog Filters and Pricing tool to manage the cost prices, or use an external system to manage the cost price list.

In this tutorial, we can manage the cost prices externally and upload them with the Catalog Filter and Pricing tool. For testing purposes, a sample cost price file is generated where the cost price of a product is set to 10% - 90% of the offer price. For example, if a product's offer price is USD $100, the cost price can be any value between USD $10 and $90. Therefore, the profit margin in this tutorial falls into the range of 10% - 90%. After creating both offer prices and cost prices, we can calculate the profit margin and index it. Normally, the indexing process in WebSphere Commerce search is divided into two stages:

  1. Preprocessing, where the highly structured relational data is flattened and stored in summary tables.

  2. The actual indexing, where data is extracted from the flattened tables and sent to the search indexes using the Data Import Handler (DIH).

We must customize the index building process to calculate the profit margin and include it into the search index by configuring the DIH configuration file. After, add support for using the profit margin as a filter and sort criteria in product recommendations by registering the field in search attribute tables with the proper property names.

We must display the profit margin data in store preview to help you verify that the correct products are being recommended. To display this profit margin in store preview, the field must be added to the mediator configuration file. We can then add the control in the JSP file to display only the fields in store preview, not in the storefront pages. Notes:


Learning objectives

After completing this tutorial, you should be familiar with the following concepts and tasks


Time required

Expect this tutorial to take 2 hours to complete. The tutorial takes longer if you explore concepts related to this tutorial.


Skill level

This tutorial is intended for advanced WebSphere Commerce developers responsible for creating and customizing WebSphere Commerce BOD services and customizing WebSphere Commerce search. To complete this tutorial, be familiar with the following terms and concepts:


Tutorial resources

Download and extract the following compressed file into a temporary directory in your development environment. This file includes the sample price data that we use in this tutorial and includes the source code used in this tutorial for reference.