Best Sellers
Module: Magenx_BestSellerGraphQl
Magento already collects best-seller statistics in its sales reports but offers none of them over GraphQL. This module adds a best-sellers list, store-wide or per category, and a “#1 Best Seller in …” badge on product cards and product pages.

How it works
Section titled “How it works”- Products are ranked by units sold, then revenue. Ranks never tie, so each category has exactly one #1.
- The badge shows a product’s best rank across the categories it belongs to, when that rank is within Maximum Badged Rank.
- Only publicly visible products rank. Disabled products, products that are “Not Visible Individually”, and products off the website are skipped, and ranks stay continuous.
- The storefront sees each product’s rank, never the units sold. Sales volume stays private.
The report period
Section titled “The report period”Report Period chooses a bucket, not a rolling window: sales so far today, this month or this year, in the store’s timezone. Early in a bucket the ranking covers only a few days. On Daily, just after midnight, it can be empty.
On a low-volume store, raise Minimum Units Sold, so a single sale in a quiet category doesn’t earn a “#1” badge.
User flows
Section titled “User flows”Best-seller rail
- The storefront asks for best sellers, optionally for a category, with a page size.
- It receives ranked items with full product data; invisible products are skipped and ranks stay contiguous.
Badges on a grid
- A category page asks for each product's badge.
- Products within the threshold get rank and their best category (id, name, URL key); others get nothing.
These always hold:
- Quantities sold are never returned.
- Only visible products are listed or badged.
- Feature off: empty list and no badges.
- Badge rank in category C = 1 + number of visible products in C that sold more.
- Bucket boundaries follow the store's time zone.
Edge cases
Section titled “Edge cases”| Situation | What happens |
|---|---|
| Daily period, just after midnight. | Possibly empty; no error. |
| Second-ranked product disabled. | Ranks 1, 2, 3 without gaps. |
| Category from another store. | Empty list. |
| Two products tie in a category. | Same badge rank. |
| No sales aggregates yet. | Empty / no badges. |
Who it applies to
Section titled “Who it applies to”- Public; scoped to the requesting store view.
Out of scope
Section titled “Out of scope”- Revenue-based or trending rankings.
- Rolling windows (rankings use the current day, month or year).
- Personalised or customer-group rankings.
- Computing the sales aggregates themselves.
Install
Section titled “Install”composer require magenxcommerce/module-best-seller-graph-qlbin/magento module:enable Magenx_BestSellerGraphQlbin/magento setup:upgradebin/magento setup:di:compile # production mode onlybin/magento cache:flush- PHP
~8.4.0||~8.5.0, Magento 2.4.8.
Configuration
Section titled “Configuration”Stores > Configuration > Magenx > Best Sellers
General
| Setting | Default | Scope | Notes |
|---|---|---|---|
Enable Best Sellersmagenx_bestseller/ | Yes | Store view | Yes/No. When disabled the bestSellers query returns empty and no product badge is resolved. |
Number of Productsmagenx_bestseller/ | 20 | Store view | Text. Shown when Enable Best Sellers = Yes. How many products the store-wide and per-category best-seller lists return. Products the storefront hides (disabled, not visible individually, or not in this website) are excluded from the ranking. |
Report Periodmagenx_bestseller/ | month | Store view | Dropdown. Shown when Enable Best Sellers = Yes. The aggregated report bucket the ranking is computed over: sales so far today, this month, or this year (in the store's timezone). Early in a bucket the ranking reflects only a partial period — on Daily, shortly after midnight, it may be empty. |
Product Badge
| Setting | Default | Scope | Notes |
|---|---|---|---|
Enable Per-Category Badgemagenx_bestseller/ | Yes | Store view | Yes/No. Show an Amazon-style "#N Best Seller in " badge on product pages. |
Maximum Badged Rankmagenx_bestseller/ | 10 | Store view | Text. Shown when Enable Per-Category Badge = Yes. A product only earns a badge when its rank in some category is at or above (numerically at or below) this value. |
Minimum Units Soldmagenx_bestseller/ | 1 | Store view | Text. Shown when Enable Per-Category Badge = Yes. A product only earns a badge when it sold at least this many units over the report period, so a single sale in a quiet category does not make it a best seller. |
With the feature off, bestSellers returns an empty list and best_seller is null.
Admin permissions
Section titled “Admin permissions”Grant these under System > Permissions > User Roles > Role Resources:
| Resource | Under | ID |
|---|---|---|
| Best Sellers Section | Stores > Settings > Configuration | Magenx_BestSellerGraphQl::config |
GraphQL
Section titled “GraphQL”ProductInterface.best_seller is resolved for a whole grid at once, so it is safe on category and search pages.
Queries
bestSellers(category_id: Int, pageSize: Int): BestSellersThe top best-selling products, store-wide or scoped to a category, ordered by quantity sold during the current bucket of the configured report period. Products the storefront does not show (disabled, not visible individually, or not assigned to this website) are excluded. Returns an empty list when the feature is disabled or the category does not belong to this store.
| Argument | Type | Description |
|---|---|---|
category_id | Int | Restrict the ranking to a single category and its descendants. Must belong to this store's category tree. Omit for the store-wide ranking. |
pageSize | Int | How many ranked products to return (capped at the store's configured best-seller count). |
Fields added to Magento types
| Field | Type | Description |
|---|---|---|
ProductInterface.best_seller | BestSellerBadge | The product's best-seller rank within its top-ranked category, or null when it does not rank within the configured threshold (or the badge is disabled). |
StoreConfig.best_seller_enabled | Boolean | Whether the best sellers feature is enabled for the store. |
StoreConfig.best_seller_count | Int | How many products the store-wide / per-category best-seller lists return. |
StoreConfig.best_seller_period | String | The report period bucket the ranking is computed over: day, month or year. |
StoreConfig.best_seller_badge_enabled | Boolean | Whether the per-category best-seller product badge is enabled. |
StoreConfig.best_seller_badge_max_rank | Int | The highest rank that still earns a best-seller badge. |
Types
type BestSellers - A ranked list of best-selling products.
| Field | Type | Description |
|---|---|---|
items | [BestSellerItem!]! | The ranked best-selling products. |
total_count | Int | The number of items returned by this request. Not the size of the full ranking. |
type BestSellerItem - A single best-selling product with its rank.
| Field | Type | Description |
|---|---|---|
rank | Int! | The 1-based position of the product in the ranking. Always contiguous: excluded products do not leave gaps. |
product | ProductInterface | The ranked product. |
type BestSellerBadge - An Amazon-style per-category best-seller badge for a product.
| Field | Type | Description |
|---|---|---|
rank | Int! | The product's 1-based rank within the category. |
category_id | Int | The id of the category the rank is for. |
category_name | String | The display name of the category. |
category_url_key | String | The URL key of the category. |
Glossary
Section titled “Glossary”| Term | Meaning |
|---|---|
| Period | Day, month or year bucket of sales aggregates. |
| Current bucket | Today / this month / this year in the store's time zone. |
| Rank | Position by quantity sold; list ranks are contiguous; tied products share a badge rank. |
| Visible product | Enabled, visible in catalog or search, sold on the store's website. |
| Badge threshold | Highest rank that still earns a badge. |
| Store category tree | Categories under the store's root category. |