How to create bestseller and top-rated labels
The Product Labels extension for Magento 2 can label products by their sales and engagement figures, and print those figures on the label. This guide creates a "Bestseller" label that shows 12 sold this month, and a "Top rated" label that shows ★ 4.5.
1. Prepare the figures
-
The figures are calculated automatically once a day, at 00:30. Right after installing or upgrading the extension, calculate them manually so you don't have to wait for the first cron run:
php -f bin/magento mirasvit:label:metric:reindex -
If you plan to use view counts, enable Stores -> Configuration -> General -> Reports -> General Options -> Enable Reports. Views are recorded only from that moment on.
2. Create the bestseller label
- Go to Marketing -> Promotions -> Product labels -> Catalog label and click New Label.
- In the General section, set Type to
Rule, and fill in Internal name, Visible in and Customer groups. - In the Rule section, click the green (+) button and select Product Popularity -> Units Sold.
- Set the operator to equals or greater than, enter a threshold (for example,
10), and choose Last 30 Days in the period selector. - In the Design section, set Title to
[units_sold_30d] sold this month, and choose a Placeholder and a Template. - Click Save.
Because the rule requires at least 10 units sold, the label never shows an empty figure. For other thresholds, see the Empty metric value setting in the General settings.
3. Create the top-rated label
- Create another Rule label.
- In the Rule section, add Product Popularity -> Average Rating, % (80% is about 4 stars), set the operator to equals or greater than and enter
80. - Add a second condition, Product Popularity -> Number of Reviews, set the operator to greater than and enter
0. Without it, the rule can also match products that have no reviews, depending on the operator you use. - Set Title to
★ [rating], choose a Placeholder and a Template, and click Save.
The rating condition uses a percentage (80 is about 4 stars), while the [rating] variable prints stars, for example 4.5.
4. Apply the labels
- If the Product Label Index is set to Update by Schedule, click Apply Label on the label edit page, or wait for the daily label cron at 00:45.
- If the index is set to Update on Save, the labels are applied when you save them.
After that, the labels are updated automatically every day, right after the figures are recalculated, with either index mode.
See Labels for how each figure is calculated, and Variables for the full list of variables.