How to configure sorting criterion
This guide describes how to create and configure sorting criterion.
To create a sorting criterion navigate to System -> Sorting criteria -> Add new.
You can find a dropdown with widely used predefined templates near this button.
1. Set general information
Type the Name into the appropriate field, set this criterion as Active to be shown on the frontend after being saved. Define, whether this criterion will be Default (applied automatically when opening a category page) and whether it will be Default for search results page. Also, you can set the Position of this criterion in the dropdown.
2. Limit the criterion to specific categories
By default, a criterion is offered in the Sort By dropdown on every category page. To offer it only on some category pages:
- Set Show in categories to
Selected categories. - In the Categories field, select the categories where the criterion should be offered.
Keep in mind how the restriction works:
- Subcategories are not included. If you select Men, the criterion is not offered on Men -> Shirts unless you select Shirts too.
- Only category pages are affected. Search results, product widgets, Page Builder product lists, search autocomplete and brand pages always offer every active criterion. A widget sorted by a restricted criterion keeps its sorting on any page.
- The category's own settings still apply. The Available Product Listing Sort By setting of the category (Catalog -> Categories -> Display Settings) narrows the list further. If no criterion is left after both rules, the category shows every criterion offered on it, as Magento does when Available Product Listing Sort By is empty.
- A page never opens with a hidden criterion. If the criterion marked as Default (or the category's Default Product Listing Sort By) is not offered on a category, that category opens with the first offered criterion by Position. The same happens when a URL requests a hidden criterion, for example
?product_list_order=codename. - Deleted categories are removed from the selection. If all selected categories are deleted, the criterion stays limited to
Selected categoriesand is not offered on any category page.
For headless storefronts, the same rule applies to the GraphQL products query filtered by category_id: a criterion hidden on that category is not returned in sort_fields.
3. Set sorting conditions
Choose the entity by which the product collection will be sorted; it can either be an Attribute or a Ranking Factor. Select the desired attribute or ranking factor from the dropdown. If a ranking factor is chosen, adjust the Weight parameter. Next, define the sorting order—results can be in ascending (ASC) or descending (DESC) order.
If necessary, add a new Sub-condition, but it must match the entity type of the first condition.
Additionally, if you want to fine-tune your sorting criteria, you can Add new condition to include extra sorting conditions.
4. Implement changes
Save the criterion and clear Magento's cache to make it visible on the frontend. Then, if it is required, execute a reindex to display the correct order of results.
If you don't clear the cache, cached category pages pick up criterion changes, including Show in categories, after the next scheduled sorting reindex. It runs every 6 hours.
Already created sorting criteria are added to the list, where you can edit or delete them.