PHPackages                             stacknuts/magento-sort-rules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. stacknuts/magento-sort-rules

ActiveMagento2-module

stacknuts/magento-sort-rules
============================

Enhance the storefront "Sort By" selector on the catalog listing toolbar with admin-configurable custom sort options, no template override or custom plugin required.

v1.0.0(today)00MITPHPPHP ~8.1.0||~8.2.0||~8.3.0||~8.4.0

Since Jul 31Pushed todayCompare

[ Source](https://github.com/StackNuts/magento-sort-rules)[ Packagist](https://packagist.org/packages/stacknuts/magento-sort-rules)[ Docs](https://github.com/StackNuts/magento-sort-rules)[ RSS](/packages/stacknuts-magento-sort-rules/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (2)Used By (0)

StackNuts Sort Rules
====================

[](#stacknuts-sort-rules)

[![Latest Version](https://camo.githubusercontent.com/8a0a24d37134349207120a02cf390649e27a39c8cddfdc3ddaa5befca58b46fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737461636b6e7574732f6d6167656e746f2d736f72742d72756c65732e737667)](https://packagist.org/packages/stacknuts/magento-sort-rules) [![License](https://camo.githubusercontent.com/2e97821f79e8a44572bccc3ecda9faa6caf0f9489d5abc67b4bfaa0ef5d142e4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f737461636b6e7574732f6d6167656e746f2d736f72742d72756c65732e737667)](https://github.com/StackNuts/magento-sort-rules/blob/main/LICENSE) [![PHP Version](https://camo.githubusercontent.com/f5813558c73ed1773f7d86784faaf0ccbb048df81b379ff098a3f30a4c882cd6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f737461636b6e7574732f6d6167656e746f2d736f72742d72756c65732e737667)](https://packagist.org/packages/stacknuts/magento-sort-rules)

Enhance the storefront "Sort By" selector on the catalog listing toolbar. This module lets you define a custom display for your sortable attributes entirely from Stores &gt; Configuration &gt; Catalog &gt; Sort Rules, no template override or custom plugin required.

[![Storefront "Sort By" dropdown showing custom options](.github/screenshots/frontend-selector.png)](.github/screenshots/frontend-selector.png)

Why
---

[](#why)

Out of the box, Magento's "Sort By" dropdown only offers a shopper "Price" plus a separate direction toggle, not "Price: High to Low" as a single click. This module lets an admin define exactly the sort options a customer sees, each with its own label, attribute, and direction, so a shopper can jump straight to what they want (prices high to low, newest first) in one click instead of two.

Installation
------------

[](#installation)

```
composer require stacknuts/magento-sort-rules
bin/magento module:enable StackNuts_SortRules
bin/magento setup:upgrade
```

Configuration
-------------

[](#configuration)

[![Sort Rules admin configuration grid](.github/screenshots/admin-config.png)](.github/screenshots/admin-config.png)

1. Go to **Stores &gt; Configuration &gt; Catalog &gt; Sort Rules**.
2. Under **General**, **Enabled** turns the module's storefront logic off entirely without losing any configured rules; while off, the "Sort By" dropdown and `product_list_order` URL parameter behave exactly as if this module weren't installed.
3. Under **Custom Sort Options**, add a row per sort option:
    - **Sort Url Param**: the identifier used in the `product_list_order` URL parameter. Doesn't need to match the attribute code, and typically shouldn't when a rule pins a specific direction (e.g. `price_desc`, `newest`). Must be unique among enabled rules; saving two enabled rows with the same value is rejected rather than silently dropping one of them.
    - **Label**: the text shown in the storefront "Sort By" dropdown.
    - **Attribute**: only attributes flagged **Used for Sorting in Product Listing** are offered here, plus **Position**, so a rule can never point at an attribute that isn't actually indexed for sorting.
    - **Display Order**: the order options appear in relative to each other in the storefront "Sort By" dropdown. Renumbered automatically on save, so rows can be reordered just by editing this value.
    - **Default Direction**: direction applied the first time the option is selected.
    - **Force Direction**: ignores any direction requested in the URL and always applies the configured one, useful for options like "Newest" that only make sense in one direction.
    - **Enabled**: disabled rows are ignored everywhere without needing to delete them.
4. Save. Rules are read from configuration at request time, not built into an index, so changes take effect immediately with no cache flush or reindex required.

**Note:** a rule replaces its attribute's plain dropdown entry, it doesn't add alongside it. Create only a "Price: High to Low" rule, and that becomes the only price option in the dropdown. To offer both directions, add two rules for the same attribute, one per direction.

The theme's toolbar template also renders a separate direction-toggle button next to the dropdown, independent of which options it lists. With **Force Direction** on, that toggle has no effect (the rule's direction always wins), but it's still visible, since removing it isn't something this module controls. To remove it, save the relevant file below as `sorter.phtml` in your own theme, replacing ``/`` with your own:

**Luma** - `app/design/frontend///Magento_Catalog/templates/product/list/toolbar/sorter.phtml`

```
