Search by

hryvinskyi / magento2-catalog-sorting-saving

hryvinskyi

Catalog sort option Biggest Saving: products with the largest discount from the regular price first, for the shopper's customer group, read from the product price index.

Package info

github.com/hryvinskyi/magento2-catalog-sorting-saving

Type:magento2-module

pkg:composer/hryvinskyi/magento2-catalog-sorting-saving

Statistics

Installs: 0

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-11-18 19:58 UTC

This package is auto-updated.

Last update: 2026-11-18 20:08:31 UTC


README

Adds Biggest Saving to the storefront Sort By list: the largest discount from the regular price first, for the shopper's customer group, per store view.

What it does for a store

  • A Biggest Saving sort order (product_list_order=saving), offered in the store views where it is enabled. A listing sorted by it opens biggest-saving first when the shopper chose no direction.
  • A saving per customer group. Each product search document holds one field per customer group, sort_saving_<customer group id>, written at index time from the product price index with one query per batch. A query sorted by saving names the field of the shopper's group, the way the platform's own price sort does.
  • Amount or percentage. Per price index row, the lowest price a group pays is the minimal price, or the tier price when it is lower. The saving is the regular price minus that, never below zero; as a percentage, that saving times 100 over the regular price. A product a group saves nothing on has no field for that group and sorts as 0.
  • No table, no refresh, nothing per request. The engine sorts on a numeric document field; there is no join and no computation per query. The customer session is started only when a query actually sorts by saving.
  • Switching the option on needs no reindex. The fields are written in every store whatever the store's Enabled setting.

Requirements

  • PHP 8.1 to 8.5.
  • hryvinskyi/magento2-catalog-sorting and hryvinskyi/magento2-catalog-sorting-options, ^1.0 each.
  • The platform's Catalog, Customer, Store, Config and Backend modules (what composer.json and etc/module.xml declare).

Installation

composer require hryvinskyi/magento2-catalog-sorting-saving
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush
bin/magento indexer:reindex catalogsearch_fulltext

The module adds a field per customer group to the product search documents. One full catalogsearch_fulltext reindex puts them into the index mapping and writes the values; listings keep working before it, and every product sorts as 0.

Configuration

Stores › Configuration › Catalog › Catalog Sorting › Biggest Saving

Path Label Default Scope
catalog_sorting/saving/enabled Enabled No default, website, store view
catalog_sorting/saving/percentage Use Percentage (No: the discount amount) No default, website, store view

Use Percentage decides which value the documents hold, so a change takes effect after a full catalogsearch_fulltext reindex. The label, the place and the visibility of the option in Sort By are set in Catalog Sorting › Sort Options.

Limits

  • The mapping declares a field for NOT LOGGED IN and for every customer group that exists when the index is created. A group added later gets its field into the mapping at the next full reindex.
  • A saving is as fresh as the price index at the last rebuild of the product's search document.

Registrations

Pool Item
providers of Hryvinskyi\CatalogSorting\Model\Index\DocumentFields saving, fields sort_saving_<customer group id> (double)
sortFields of Hryvinskyi\CatalogSorting\Model\Search\ShopperSortFields saving, Model\SavingShopperSortField: code saving on the current group's field
options of Hryvinskyi\CatalogSortingOptions\Model\ListingSortOptions option saving, "Biggest Saving", descending, sortOrder 160