Skip to content

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.

The storefront best sellers page
The /best-sellers page on the demo store.
  • 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.

Orders

Sales report statistics
(daily / monthly / yearly)

Rank per store and category

bestSellers list

#1 Best Seller in Category badge

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.

Best-seller rail

  1. The storefront asks for best sellers, optionally for a category, with a page size.
  2. It receives ranked items with full product data; invisible products are skipped and ranks stay contiguous.

Badges on a grid

  1. A category page asks for each product's badge.
  2. 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.
SituationWhat 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.
  • Public; scoped to the requesting store view.
  • 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.
Terminal window
composer require magenxcommerce/module-best-seller-graph-ql
bin/magento module:enable Magenx_BestSellerGraphQl
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
  • PHP ~8.4.0||~8.5.0, Magento 2.4.8.

Stores > Configuration > Magenx > Best Sellers

General

SettingDefaultScopeNotes
Enable Best Sellers
magenx_bestseller/general/enabled
YesStore viewYes/No. When disabled the bestSellers query returns empty and no product badge is resolved.
Number of Products
magenx_bestseller/general/count
20Store viewText. 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 Period
magenx_bestseller/general/period
monthStore viewDropdown. 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

SettingDefaultScopeNotes
Enable Per-Category Badge
magenx_bestseller/badge/enabled
YesStore viewYes/No. Show an Amazon-style "#N Best Seller in " badge on product pages.
Maximum Badged Rank
magenx_bestseller/badge/max_rank
10Store viewText. 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 Sold
magenx_bestseller/badge/min_qty
1Store viewText. 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.

Grant these under System > Permissions > User Roles > Role Resources:

ResourceUnderID
Best Sellers SectionStores > Settings > ConfigurationMagenx_BestSellerGraphQl::config

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): BestSellers

The 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.

ArgumentTypeDescription
category_idIntRestrict the ranking to a single category and its descendants. Must belong to this store's category tree. Omit for the store-wide ranking.
pageSizeIntHow many ranked products to return (capped at the store's configured best-seller count).

Fields added to Magento types

FieldTypeDescription
ProductInterface.best_sellerBestSellerBadgeThe 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_enabledBooleanWhether the best sellers feature is enabled for the store.
StoreConfig.best_seller_countIntHow many products the store-wide / per-category best-seller lists return.
StoreConfig.best_seller_periodStringThe report period bucket the ranking is computed over: day, month or year.
StoreConfig.best_seller_badge_enabledBooleanWhether the per-category best-seller product badge is enabled.
StoreConfig.best_seller_badge_max_rankIntThe highest rank that still earns a best-seller badge.

Types

type BestSellers - A ranked list of best-selling products.
FieldTypeDescription
items[BestSellerItem!]!The ranked best-selling products.
total_countIntThe number of items returned by this request. Not the size of the full ranking.
type BestSellerItem - A single best-selling product with its rank.
FieldTypeDescription
rankInt!The 1-based position of the product in the ranking. Always contiguous: excluded products do not leave gaps.
productProductInterfaceThe ranked product.
type BestSellerBadge - An Amazon-style per-category best-seller badge for a product.
FieldTypeDescription
rankInt!The product's 1-based rank within the category.
category_idIntThe id of the category the rank is for.
category_nameStringThe display name of the category.
category_url_keyStringThe URL key of the category.
TermMeaning
PeriodDay, month or year bucket of sales aggregates.
Current bucketToday / this month / this year in the store's time zone.
RankPosition by quantity sold; list ranks are contiguous; tied products share a badge rank.
Visible productEnabled, visible in catalog or search, sold on the store's website.
Badge thresholdHighest rank that still earns a badge.
Store category treeCategories under the store's root category.