Demo extension available here https://github.com/ajourquin/module-custom-product-sorting

Default product sorting list

Magento has 4 default sorting options: Name, Price, Position and Relevance.

Sorting are product attributes, except for “position” in catalog pages and “relevance” in search pages

You can add new product attributes to the sorting list by selecting the attribute you want to sort by in admin and set field “Used for Sorting in Product Listing” to “Yes” under “Storefront properties” tab.

Position corresponds to order set by products in category under “Products in Category” section. Can be set manually or via visual merchandising (Magento Commerce only).

Relevance corresponds to score of product for a search.


Default sorting by category

The default product sorting for all categories is set under
Stores > Configuration > Catalog > Catalog > Storefront > Product Listing Sort by

You can choose a different default product sorting by category.
Set “Default Product Listing Sort By” to the sorting you want as default under “Display Settings” in an edit category page in admin


Add custom sorting

1- Add the custom value in frontend sorting list

\Magento\Catalog\Model\Config::getAttributeUsedForSortByArray is responsible to populate the product sorting dropdown


So to add your custom value just create an after plugin afterGetAttributeUsedForSortByArray


2- Add the custom value in config sorting list

\Magento\Catalog\Model\Config\Source\ListSort::toOptionsArray is responsible to populate the product sorting dropdown.
Stores > Configuration > Catalog > Catalog > Storefront > Product Listing Sort by


Create an after plugin afterToOptionArray to add the custom value

Now you are able to select the Custom Value sorting by default for all categories


3- Add the custom value in category edit page

\Magento\Catalog\Model\Category\Attribute\Source\Sortby::getAllOptions is responsible to populate the dropdown for “Default Product Listing Sort By” field


Create an after plugin afterGetAllOptions to add the custom value

Now you are able to select the Custom Value sorting by default for a specific category

4- Sort products

There are different places where you can sort products collection using plugins.

You can use a before plugin on \Magento\Catalog\Model\Layer::prepareProductCollection in frontend area

That’s it!