Meetanshi Docs Magento 2 Improved Sorting

Improved Sorting for Magento 2 - User Guide

Meetanshi Improved Sorting extends Magento's product sorting with 19 strategies, product pinning, pre-built indexes, and OpenSearch and GraphQL support. This guide covers installation, configuration, every admin field, the sorting strategies, product pinning, indexers, CLI commands, the REST API, cron, and troubleshooting.

Extension Installation
  1. Extract the ZIP file and upload the extension to the root of your Magento 2 directory via FTP.
  2. Log in to your server via SSH and run:
    php bin/magento setup:upgrade
  3. Deploy static content and flush cache
    php bin/magento setup:static-content:deploy -f
    php bin/magento cache:flush

What happens on install

During setup:upgrade, a data patch (InitialReindex) runs automatically and back-fills all 7 sort index tables from your existing store data (orders, views, wishlists, ratings, reviews). No manual reindex is needed on a fresh install.

Post-Install Checklist

  1. Go to Stores > Configuration > Meetanshi > Improved Sorting and enable the module.
  2. Set your default sort options for category and search pages.
  3. Enable index-based sorting (Use Index = Yes) for large catalogs.
  4. Run bin/magento indexer:reindex if the initial data patch was skipped.
  5. Confirm the daily cron (0 2 * * *) is present in your cron schedule.

Configuration: General Settings

Go to Stores > Configuration > Meetanshi > Improved Sorting > General Settings.

Field Default Description
Enable Module Yes Master switch. When No, custom sorting is off and Magento defaults are restored.
Apply Sorting for All Collections No When Yes, strategies also apply to widgets, related products, upsells, and other collections, not just category and search.
Default Sort by on Category Page (select) The sort is pre-selected on category pages before the customer chooses one.
Default Sort by on Search Page (select) The sort pre-selected on search result pages.
Hide Position Sorting Option on Frontend No Removes Magento's native Position option from the sort dropdown.
Show Out-of-Stock Products in Last Disabled Moves out-of-stock products to the end. Mode 1 uses stock status, Mode 2 uses quantity below 1.
Show Products Without Images in Last No Moves products with no thumbnail to the end of results.
Use Qty to Determine If Products Are Out of Stock No Used with out-of-stock mode. When Yes, quantity below 1 is the threshold instead of the stock status flag.

Image

Field Default Description
Disable Sorting Options (none) Removes selected strategies from the dropdown and from all processing.
Sort Attributes Descending by Default (none) Forces selected strategies to default to descending on first load.
Use Index for Bestsellers / Most Viewed / Wishlists Yes When Yes, behavioral sorts read from pre-built index tables instead of running live joins. Recommended for production.
Developer Mode No Adds debug output to var/log/meetanshi_improvedsorting.log.
Debug Product Meta Data No Adds sort score data as HTML comments in product list items for frontend debugging.

Image

Configuration: SEO Settings

Found under the same configuration screen.

Field Default Description
Meta Robots Tag for Sorted URLs NOINDEX,FOLLOW The robots meta value added on category and search pages when a non-default sort is active. Keeps sort parameter URLs out of the index.
Canonical Tag Mode Default URL Controls the canonical on sorted pages: Default URL (canonical is the category URL without sort params), Current URL (canonical includes sort params), or Disabled.

Image

Configuration: Per-Strategy Settings

Each sorting strategy has its own group in the configuration. Most strategies share these fields:

  • Enable: show or hide the option in the frontend dropdown.
  • Label: a custom frontend label. If empty, the default label is used.
  • Default Direction: ASC or DESC when the customer has not chosen a direction.
  • Sort Order: the position of the option in the dropdown (lower appears first).

Image

Some strategies add their own fields:

  • Bestsellers: Period (days, 0 = all time) and Exclude Order Statuses (default: canceled, closed).
  • Most Viewed: Period (days).
  • Now in Wishlists: Period (days).
  • Reviews Count: Reviews Source (All or Approved only).
  • Newest: Date Source (created_at, updated_at, or news_from_date).
  • Biggest Saving: Sort by Percentage (Yes = discount percent, No = absolute amount).
  • Profit: Cost Attribute Code (default cost) and Price Attribute Code (default price).

Product Pinning (Pin Products to Top)

Pinning forces specific products to the top of a category or search result, regardless of the active sort. Pinned products keep their relative order.

Pin from the category page

  1. Go to Catalog > Categories and open a category.
  2. Scroll to the Pinned Products (Improved Sorting) fieldset.
  3. Enter a comma-separated list of product IDs in the order you want.
  4. Save the category.

Image

View pins in the grid

Go to System > Improved Sorting > Pin Products to Top. The grid lists all active pins with ID, Product ID, SKU, Category ID, Category, Store ID, and Position. This grid is read-only for audit. Pins are created from the category form or the REST API.

Image

How pinning behaves

  • On category pages, pinned products are placed first in the SQL order.
  • On search pages, pinned products are boosted in OpenSearch so they reach page one, then reordered to the top.
  • In GraphQL category queries, pinned products are moved to the front in pin order.

Improved Sorting on Frontend

The enabled sorting options are enabled on the category and search result pages as per the configuration from the backend.

Image

Indexers

The module registers 7 indexers, each pre-aggregating one sort metric into a flat table so behavioral sorts avoid slow live joins.

Reindex from the CLI:

# Reindex all Improved Sorting indexers
bin/magento meetanshi:improvedsorting:reindex

# Or reindex the individual Magento indexers
bin/magento indexer:reindex meetanshi_improvedsorting_bestsellers \
meetanshi_improvedsorting_mostviewed \
meetanshi_improvedsorting_wishlist \
meetanshi_improvedsorting_recentordered \
meetanshi_improvedsorting_avgview \
meetanshi_improvedsorting_toprated \
meetanshi_improvedsorting_reviewscount

# Check indexer status
bin/magento indexer:status

The 7 indexers cover bestsellers, most viewed, wishlist, recent ordered, average view per sale, top rated, and reviews count. They update in near real time through Magento's Mview (the indexer_update_all_views cron), and a full rebuild runs from the daily cron.

CLI Commands

Run from the Magento root.

Command Purpose
meetanshi:improvedsorting:reindex Full reindex of all 7 sort indexers. Add --format=json for JSON output.
meetanshi:improvedsorting:status Reports module configuration and lists enabled sort options. Supports --format=json.
meetanshi:improvedsorting:pin:list Lists active pins. Filter with --category=<id> or --product=<id>, or use --format=json.
meetanshi:improvedsorting:cache:clean Clears extension-specific cache entries.
meetanshi:improvedsorting:export-config Exports current configuration as JSON. Use --output=/path/to/config.json to write to a file.
meetanshi:improvedsorting:import-config <file> Imports configuration from a JSON file. Run bin/magento cache:clean config afterward.

REST API

Base URL: /rest/V1/meetanshi-improvedsorting/. Authentication uses Magento's standard OAuth or bearer token.

  • GET /options (public): returns the list of enabled sorting options for a store.
  • POST /pin (admin token, resource Meetanshi_ImprovedSorting::improvedsorting_pin): creates a pin. Body: productId (required), categoryId (required), position (default 0), storeId (default 0).
  • DELETE /pin/:pinId (admin token): deletes a pin by its ID.
  • POST /reindex (admin token, resource Meetanshi_ImprovedSorting::improvedsorting_config): triggers a full reindex of all 7 indexers.

Example pin request body:

{
"productId": 42,
"categoryId": 7,
"position": 0,
"storeId": 0
}

Cron and Auto-Refresh

A daily cron, meetanshi_improvedsorting_reindex_daily, runs at 0 2 * * * (2:00 AM). It rebuilds all 7 index tables, then marks the search index invalid so Magento's search reindex pushes the fresh sort scores into OpenSearch or Elasticsearch. Make sure Magento cron is running (bin/magento cron:run).

Updated: Jun 21, 2026Top ↑