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.
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
- The customer browses a category in the Storefront, invoking the BrowsingService.
- BrowsingService calls TopSellerService.findTopSellerByCategoryUid(categoryUid) to retrieve a category's list of top-selling products.
- BrowsingService populates a BrowsingResult with TopSellingProducts and returns.
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:
- 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.
- Loop through the list of orders and get the sales count of all SKUs belonging to the same product since the previous calculation date.
- Update the existing sales count of the product by adding the new sales count and save the updated Product.
- 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")