Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Top sellers

Top sellers

The Storefront can display and sort a list of top-selling products on the category page. A Quartz job in the Commerce Manager calculates top sellers by evaluating product sales counts.

In the code, a category has no direct knowledge of its TopSellers; a TopSeller object maintains a list of top selling products for a category. To retrieve a category's list of TopSellers, you pass in the Category's UID to the TopSellerService method.

Key classes and files

In Core:

  • TopSeller - A list of top selling products for a given category.
  • TopSellerProduct - A representation for a top selling product.
  • TopSellerService - A service for calculating top sellers and storage/retrieval of TopSeller objects.
  • topSeller.properties - A properties file that stores the previous TopSellers calculation date.
  • OrderService - A service for Order tasks. The OrderService handles Order retrieval for the TopSeller service.
  • ProductService - A service for Product tasks. The ProductService handles the storing and retrieval of Products for the TopSeller service.

In Store Assets:

  • topsellers.vm - A Velocity template that displays the configured number of top selling products.

Database structure

Top Sellers uses two database tables to store data:

  • TTOPSELLER - Maps TopSellers to Catalog categories.
  • TTOPSELLERPRODUCTS - Maps TopSellerProducts to TopSellers.

How it works

Top Seller Display

  1. The customer browses a category in the Storefront, invoking the BrowsingService.
  2. BrowsingService calls TopSellerService.findTopSellerByCategoryUid(categoryUid) to retrieve a category's list of top-selling products.
  3. BrowsingService populates a BrowsingResult with TopSellingProducts and returns.
Note:

For more information on how BrowsingService works, see Catalog browsing.

Top Seller Calculation

TopSellerService uses the algorithm in updateTopSellers() to update the sales counts of products that were purchased since the previous calculation:

  1. Retrieve the previous TopSeller calculation date from the topSeller.properties file in the Core's resources/resources directory.
    • If last processed date is null, the calculation has never been done, so retrieve all orders using the OrderService.
    • Else retrieve all orders since the previous calculation date using the OrderService.
  2. Loop through the list of orders and get the sales count of all SKUs belonging to the same product since the previous calculation date.
  3. Update the existing sales count of the product by adding the new sales count and save the updated Product.
  4. Update the last processed date to current date and save to topSeller.properties.

Configuring the Top Seller calculation job

The Top Seller calculation schedule is configurable via the Commerce Manager's quartz configuration file.

To display TopSellers in other Velocity templates, use the following Velocity directive:

#parse("includes/topsellers.vm")