hryvinskyi / magento2-catalog-sorting-bestsellers
Catalog sort option Best Sellers: the products with the most units ordered in a recent period first, computed by the daily popularity data refresh.
Package info
github.com/hryvinskyi/magento2-catalog-sorting-bestsellers
Type:magento2-module
pkg:composer/hryvinskyi/magento2-catalog-sorting-bestsellers
Requires
- php: ~8.1.0||~8.2.0||~8.3.0||~8.4.0||~8.5.0
- hryvinskyi/magento2-catalog-sorting: ^1.0
- hryvinskyi/magento2-catalog-sorting-metrics: ^1.0
- hryvinskyi/magento2-catalog-sorting-options: ^1.0
- magento/framework: *
- magento/module-backend: *
- magento/module-catalog: *
- magento/module-config: *
- magento/module-sales: *
- magento/module-store: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Adds Best Sellers to the storefront Sort By list: the products with the most units ordered first, per store view.
What it does for a store
- A Best Sellers sort order (
product_list_order=bestsellers), offered in the store views where it is enabled. A listing sorted by it opens best-first when the shopper chose no direction. - Units ordered, per store. A product's value in a store is the sum of
qty_orderedof its order items in that store's orders created within the period, leaving out orders in the excluded statuses. Each order item counts for its own product: the row of a configurable product credits the configurable, the row of the child that was bought credits the child. - Computed once a day, not per request. The value is one aggregate query over the order tables, run by the popularity data refresh of
hryvinskyi/magento2-catalog-sorting-metrics. Only products whose value changed get their search documents rebuilt. - Sorted in the search engine on the numeric document field
sort_bestsellers; no join and no computation per query. A product without orders in the period sorts as 0, so best-first puts it last.
Requirements
- PHP 8.1 to 8.5.
hryvinskyi/magento2-catalog-sorting,hryvinskyi/magento2-catalog-sorting-optionsandhryvinskyi/magento2-catalog-sorting-metrics, ^1.0 each.- The platform's Sales, Catalog, Store, Config and Backend modules (what
composer.jsonandetc/module.xmldeclare).
Installation
composer require hryvinskyi/magento2-catalog-sorting-bestsellers bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush bin/magento indexer:reindex catalogsearch_fulltext
The module adds the field sort_bestsellers to the product search documents. One full catalogsearch_fulltext reindex puts it into the index mapping; listings keep working before it. After enabling the option in a store view, run bin/magento catalog-sorting:metrics:refresh --metric=bestsellers, or wait for the next scheduled refresh.
Configuration
Stores › Configuration › Catalog › Catalog Sorting › Best Sellers
| Path | Label | Default | Scope |
|---|---|---|---|
catalog_sorting/bestsellers/enabled |
Enabled | No | default, website, store view |
catalog_sorting/bestsellers/period |
Period, Days (0 counts all orders) | 183 | default |
catalog_sorting/bestsellers/excluded_statuses |
Exclude Orders With Status | canceled |
default |
The label, the place and the visibility of the option in Sort By are set in Catalog Sorting › Sort Options. The refresh schedule is in Catalog Sorting › Popularity Data Refresh.
Registrations
| Pool | Item |
|---|---|
metrics of Hryvinskyi\CatalogSortingMetrics\Model\MetricRegistry |
metric bestsellers, field sort_bestsellers (double) |
sortFields of Hryvinskyi\CatalogSorting\Model\Search\ShopperSortFields |
code bestsellers on sort_bestsellers |
options of Hryvinskyi\CatalogSortingOptions\Model\ListingSortOptions |
option bestsellers, "Best Sellers", descending, sortOrder 100 |