Getting Started

Welcome to the Improved Sorting documentation. Whether you are new or an advanced user, you can find some useful information here.

First of all, we recommend that you check the following link:

How to install the extension

  1. Back up your store's database and web directory.
  2. Log in to the SSH console of your server and navigate to the root directory of the Magento 2 store.
  3. Copy the installation instructions from the page My Downloadable Products to the SSH console and press ENTER.
  4. Run the command php -f bin/magento module:enable Mirasvit_Core Mirasvit_Sorting to enable the extension.
  5. Run the command php -f bin/magento setup:upgrade to install the extension.
  6. Run the command php -f bin/magento cache:clean to clean the cache.
  7. Deploy static view files

    rm -rf pub/static/*; rm -rf var/view_preprocessed/*; php -f bin/magento setup:static-content:deploy

Ranking Factors

Ranking Factor - internal functionality that can be used for sorting criteria.

Go to System > Improved sorting > Ranking Factors. You will see the available factors. You can add a Factor by pressing the Add New button. You will then see a ranking factor dialog, which contains basic data:

General information:

  • Type * - data type. Check the details below;
  • Name * - internal name;
  • Active - ability to enable / disable;
  • Global - the global factor will be applied before all other conditions for all Sorting Criteria. Global factors have the highest priority. The extension sorts any product collection by global factors. It then sorts by scoring factors (if any kind of sorting criteria were applied).

Configuration:

Depending on data type:

  • Date - Ranks products based on Created At/Updated At date;
    • Creation date - when the product was added to the database;
    • Updating date - when the product was most recently updated;
    • Zero point - Number of days the Created At/Updated At date influences the products ranking.

      Note

      It is recommended that you use a value from 1 to 100. For example, if set at 100, then the products which were created/updated more than 100 days prior will receive a positive Score (the earlier, the higher), and products which were created/updated less than 100 days prior will receive a score of zero.
    • Attribute set - Ranks products based on an attribute set.
    • Mapping - allows for assigning a weight to a set of attributes to participate in sorting;
      • Attribute Set - attributes set;
      • Weight - the weight. It is recommended that you use a value from 1 to 100.
    • Attribute - allows for assigning a weight to attributes to participate in sorting;
    • Mapping
      • Option - the internal name of a ranking factor, used for Sorting Criteria configuration;
      • Weight - the weight. It is recommended that you use a value from 1 to 100.
    • Image - rank products based on image availability;
    • Product Rating - ranks products based on overall rating;
    • Bestseller - ranks products based on the number of purchases within the period of time;
    • Past Days - number of days the order date has influence on products ranking. By default, it is 60;
    • Profit - calculation: the products price and cost determines the products ranking of this factor;
    • Rule - ranks products based on various different conditions;
    • Conditions - allows for selecting Product Attribute. Leave blank for all products;
    • Stock status - ranks products based on stock status.
    • SPV = Sales Pre View = Number of Sales / Number of Product Page Views;
    • Zero point - number of days that influence products ranking. It is recommended that you use a value from 1 to 100.
    • Popularity - ranks products based on the number of product page views;
    • Discount - calculation: the difference between the regular price and special prices.

Note

After creating or making changes, make a re-index. You can use the Reindex button for this, or run the reindex with the cli commands.

Sorting Criteria

Go to System > Improved Sorting > Sorting Criteria.

You will see the list of configured sorting options. If the list is empty, Magento will use the default sorting options.

Here you can change the order of the criteria visible to users and add/remove available options.

Once you add your first sorting criteria, the extension will replace native Magento sorting options and use your configuration.

To add new Criteria click Add new button.

General information:

  • Name * - name of option, visible in the dropdown on front-end;
  • Active - to enable/disable criteria;
  • Default - applies sorting criteria by default on the category page;
  • Default for Search - applies the sorting criteria by default on the search results page (instead of sorting by relevance);
  • Position - position of sorting option in the dropdown on front-end.
  • Conditions - describes the logic for sorting products. You can use:
    • Catalog attributes - an attribute is visible for sorting, if the option Used for Sorting in Product Listing is enabled (Stores > Attributes > Product);
    • Ranking factors - allows for choosing one of the Ranking Factors;
    • ASC (A-Z, 0-9)/DESC (Z-A, 9-0) - allows for sorting from smallest to largest/ from largest to smallest;
    • Weight - allows for increasing the impact of the factor in a particular rule that is set with the value from 1 - 100;
    • Limit - sets the maximum number of products for which this weight will be applied;
  • Add New Sub Condition button - allows for adding several criteria and setting their weight in the current group of conditions. Affects the position of a product in a category.

    Note

    Product Score = SubConditionWeight1 + SubConditionWeight2 + SubConditionWeightN

    The extension will calculate, assign each item its own Score, and place them in ascending or descending order. For example, let's apply sorting by creation date and stock availability:

    • Product E (28.10.2020, in stock)
    • Product C (25.10.2020, in stock)
    • Product A (20.10.2020, in stock)
    • Product D (25.10.2020, out of stock)
    • Product F (20.10.2020, out of stock)
    • Product B (18.10.2020, out of stock)
  • Add New Condition button - allows for setting the sort sequence; affects the product position in the product group and in the category;

    Note

    Product Score = Condition1(SubConditionWeight1 + SubConditionWeight2 + SubConditionWeightN) + Condition2(SubConditionWeight1 + SubConditionWeight2 + SubConditionWeightN)

    It will sequentially sort the products, first by the first condition and then by the subsequent conditions within the group. Lets arrange the products, for example, by creation date and then by stock availability for the specified date:

    • Product E (28.10.2020, in stock)
    • Product C (25.10.2020, in stock)
    • Product D (25.10.2020, out of stock)
    • Product A (20.10.2020, in stock)
    • Product F (20.10.2020, out of stock)
    • Product B (18.10.2020, out of stock)
  • Advanced Configuration:

    • Code - used to generated a URL; does not affect anything else.

    Sorting for Widgets

    The extension allows you to manage the sorting in Default Magento Widgets.

    How to add a new widget

    • Open Content > Elements > Widgets > Add new
    • In the Widgets options tab, choose Sorting Criteria in the Sort by field.

    New Widget

    Debugging

    To check the product position in the backend, use the Preview button when creating a Ranking Factor or Sorting Criteria.

    Preview

    To check the product position in the frontend, use ?debug=sorting in the page URL. This allows you to see the score for each product.

    • Global Score - the score which the product obtained after global rules were applied;
    • Sorting Score - the score which the product obtained after sorting by Sorting Criteria;
    • Sorting SubScore - the score which the product obtained after sorting by SubConditional.

    Debugging

    Command Line Interface

    Usage: php -f bin/magento [options]

    • mirasvit:sorting:reindex - reindex extension indexes as you would for the native Magento 2 command: indexer:reindex mst_sorting

    How To

    Contents

    How can I translate the sorting label to different languages

    The extension uses the same logic for translations as default Magento. More details: https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/translations/xlate.html)

    Our i18n files should be located at: vendor/mirasvit/module-sorting/src/Sorting/i18n/

    Create a separate file for your language (en_US.csv, de_DE.csv). The names for all languages can be found via this command:

    php -f bin/magento info:language:list

    Override the strings in your dictionary file:

    "Original line" , "Translated line"

    Run this command to see the changes:

    php -f bin/magento setup:static-content:deploy

    php -f bin/magento cache:flush

    The custom themes will be displayed instead of the default for your language.

    How can I set different sorting criteria for my categories?

    You can use different sorting criteria for different categories. To do this, go to Catalog > Categories > YourCategoryName > Display Settings > Available Product Listing Sort By and set the required sorting criteria for this category.

    Also, you can set default sorting for this category. Please use the Default Product Listing Sort By option.

    How to upgrade extension

    To upgrade the extension, take the following steps:

    1. Back up your store's database and web directory.
    2. Log in to the SSH console of your server and navigate to the root directory of the Magento 2 store.
    3. Run the command composer require mirasvit/module-sorting:* --update-with-dependencies to update the current extension with all dependencies.

      Note

      In some cases, the command above is not applicable, as you are unable to update just the current module, and so need to upgrade all Mirasvit modules in a bundle. In this case, the command above will have no effect.

      Instead, run the composer update mirasvit/* command. It will update all Mirasvit modules installed on your store.

    4. Run the command php -f bin/magento setup:upgrade to install updates.
    5. Run the command php -f bin/magento cache:clean to clean the cache.
    6. Deploy static view files

      rm -rf pub/static/*; rm -rf var/view_preprocessed/*; php -f bin/magento setup:static-content:deploy

    Disabling the Extension

    Temporarily Disable

    To temporarily disable the extension, please take the following steps:

    1. Log in to the SSH console of your server and navigate to the root directory of the Magento 2 store.
    2. Run the command php -f bin/magento module:disable Mirsvit_Sorting to disable the extension.
    3. Log in to the Magento back-end and refresh the store cache (if enabled).

    Removing the Extension

    To uninstall the extension please take the following steps:

    1. Log in to the SSH console of your server and navigate to the root directory of the Magento 2 store.
    2. Run the command composer remove mirasvit/module-sorting to remove the extension.
    3. Log in to the Magento back-end and refresh the store cache (if enabled).

    1.1.14

    (2021-11-23)

    Improvements

    • New Ranking Factor: Backorders
    • New Feature: Popularity (number of usages) of sorting criterias

    Fixed

    • Amasty Elasticsearch compatibility
    • Relevance sort dirrection issue after add position criteria

    1.1.13

    (2021-10-29)

    Fixed

    • Stock status ranking factor issue
    • Fixed the issue with sorting by position

    1.1.12

    (2021-09-20)

    Fixed

    • Out of stock ranking factor missing products
    • Missing scores while indexing

    1.1.11

    (2021-08-13)

    Improvements

    • Alphanumeric sorting on multistore environment

    1.1.10

    (2021-08-13)

    Improvements

    • Added alphanumeric ranking factor
    • Added "New From Date" to date ranking factor

    1.1.9

    (2021-08-06)

    Fixed

    • SQL error with unknown sorting direction

    1.1.8

    (2021-07-20)

    Fixed

    • Error on attribute set API request
    • Improve StockQtyFactor to apply child products qty

    1.1.7

    (2021-05-26)

    Fixed

    • Criteria reverse order

    1.1.6

    (2021-04-14)

    Fixed

    • fixed the issue with 'relevance' code for sorting criteria
    • indexing issue

    1.1.4

    (2021-04-05)

    Fixed

    • Sorting by store view (sql)

    1.1.3

    (2021-04-01)

    Fixed

    • option getlabel issue

    1.1.2

    (2021-03-04)

    Improvements

    • Ability to define default sort order using native Catalog Configuration options

    1.1.1

    (2021-01-27)

    Improvements

    • Default sort direction

    Fixed

    • Issue with selecting image attribute (non-default entity type id)

    1.1.0

    (2020-12-30)

    Improvements

    • Reindex sorting indexes after product change

    Fixed

    • Fixed the issue with the error: Deprecated Functionality: Array and string offset access syntax with curly braces is deprecated

    1.0.58

    (2020-12-22)

    Fixed

    • Issue with REAS API (Magento 2.3)

    1.0.57

    (2020-12-07)

    Improvements

    • Set direction for widgets

    1.0.56

    (2020-12-04)

    Fixed

    • Issue with applying sorting on custom collections
    • Sorting for REST API

    1.0.54

    (2020-11-27)

    Improvements

    • Developer Mode flag

    Fixed

    • Issue with types

    1.0.53

    (2020-11-24)

    Fixed

    • Compatibility with Olegnax_LayeredNavigation
    • Minor fixes

    1.0.51

    (2020-11-23)

    Improvements

    • Removed compatibility with Magento 2.1, 2.2 (PHP 7.1+)
    • Improved module performance

    1.0.50

    (2020-10-12)

    Improvements

    • Quantity in the sorting preview

    1.0.49

    (2020-10-08)

    Features

    • New ranking factor "Stock Quantity"

    1.0.48

    (2020-09-23)

    Features

    • Pre-ready sorting criteria

    Fixed

    • Score on preview page

    1.0.47

    (2020-09-09)

    Improvements

    • Ranking Factor Precision

    1.0.46

    (2020-08-19)

    Refactor

    • Improved module structure

    1.0.45

    (2020-08-11)

    Fixed

    • Compatibility issue with ElasticSearch

    1.0.44

    (2020-07-29)

    Improvements

    • Support of Magento 2.4

    1.0.43

    (2020-06-30)

    Fixed

    • Issue with default sorting not applied on brand pages (Mirasvit_Brand module).

    1.0.42

    (2020-05-15)

    Fixed

    • Issue with sorting by position attribute when Use Flat Catalog Product enabled
    • Issue with sorting collection at the Advanced Product Feed module

    Features

    • NO_SORT flag for product collections in custom blocks.
    • Ability to disable sorting for custom blocks in the configurations.

    1.0.41

    (2020-04-14)

    Fixed

    • Issue with sorting by attribute with the type boolean/dropdown ("You cannot define a correlation name '...' more than once").
    • Issue with inactive criteria used for sorting in custom blocks

    1.0.40

    (2020-03-27)

    Fixed

    • Issue with widgets with random products order (Cannot use object of type Zend_Db_Expr as array. Affects only 1.0.39)

    1.0.39

    (2020-03-26)

    Fixed

    • Issue with sorting in widgets when elasticsearch is used

    1.0.38

    (2020-03-23)

    Fixed

    • Issue with default Magento order for attributes (duplicated fields in ORDER BY clause)

    1.0.37

    (2020-03-16)

    Features

    • New ranking factor "New products" based on "Set product as new from ... to ..." attribute

    1.0.36

    (2020-02-28)

    Fixed

    • Error in some cases. Cannot use object of type Zend_Db_Expr as array. Affects only 1.0.35

    1.0.35

    (2020-02-27)

    Improvements

    • Discount ranking factor calculation for configurable/bundle/grouped products

    Fixed

    • Sorting by name (only M2.3.4)
    • subconditions for sort by attribute

    1.0.34

    (2020-02-21)

    Fixed

    • Apply sorting only on frontend

    1.0.33

    (2020-02-12)

    • Improve debug widget
    • Added custom sorting fix
    • Fixed calculation of price factor (for complex product types)

    1.0.32

    (2020-02-06)

    Fixed

    • Default sorting field
    • Missing positionOrderApplied variable when global sorting applied
    • Wrong product position when position sort order applied
    • Bestseller score factor indexing issue
    • Unable to apply sort by name

    1.0.29

    (2019-12-30)

    Improvements

    • Code refactoring

    Fixed

    • Sort by name issue

    1.0.28

    (2019-11-25)

    Fixed

    • Elasticsearch compatibility

    1.0.27

    (2019-11-21)

    Improvements

    • Admin styles

    1.0.26

    (2019-11-07)

    Fixed

    • Disable sorting of products collection in CLI mode (prevent possible indexation issue)
    • Issue during indexation Discount Ranking Factor
    • Unexpected indexer dependency

    1.0.25

    (2019-10-10)

    Fixed

    • Compatibility with native ES

    1.0.24

    (2019-09-02)

    Fixed

    • Compatibility with EE Elasticsearch

    1.0.23

    (2019-07-25)

    Improvements

    • Debug mode

    Fixed

    • Possible issue with second join (temporary table)
    • Popularity factor

    1.0.22

    (2019-05-20)

    Fixed

    • Issue with sorting if criteria/factor is empty
    • Issue with applying custom sorting for category

    1.0.21

    (2019-05-16)

    Improvements

    • integration with Autocomplete
    • Rating Factor. Use also number of ratings

    1.0.20

    (2019-04-17)

    Improvements

    • Conditions column in criteria listing
    • Enabled Inline Editor
    • Search results sorting

    1.0.19

    (2019-04-10)

    Improvements

    • Inline debug interface (&debug=sorting)

    1.0.18

    (2019-04-08)

    Fixed

    • Compatibility issue with Magento Enterprise

    1.0.17

    (2019-04-01)

    Improvements

    • Ability to use native "Position" as sorting attribute

    1.0.16

    (2019-03-27)

    Improvements

    • Ability to defined limits

    Fixed

    • Error during indexation of sorting index if an attribute is not set in a rating factor
    • By default sort direction is set to the direction of a default criterion, even when custom direction used

    1.0.15

    (2019-03-19)

    Fixed

    • Compatibility with Magento 2.1.x

    1.0.14

    (2019-03-18)

    Fixed

    • Attribute sort direction does not change
    • Saving sorting code

    1.0.13

    (2019-03-11)

    Improvements

    • Popularity Factor
    • Discount Factor
    • Preview interface

    1.0.12

    (2019-03-07)

    Improvements

    • Ability to use sorting for catalog widget "Catalog Products List"

    Fixed

    • Sort direction does not change

    1.0.11

    (2019-03-04)

    Improvements

    • Changed sorting interface

    1.0.10

    (2019-02-22)

    Improvements

    • Add module translation file mirasvit/module-navigation[#79]()

    1.0.9

    (2019-02-11)

    Fixed

    • System settings page not loaded after adding a new attribute to sorting

    1.0.8

    (2019-01-10)

    Fixed

    • Conflict with Mirasvit Search module: searching products fails with error (since 1.0.7)

    1.0.7

    (2019-01-09)

    Features

    • Push 'out of stock' products to the end of a list

    Documentation

    • Info about new settings

    1.0.7

    (2019-01-08)

    Features

    • Push 'out of stock' products to the end of a list

    1.0.6

    (2018-12-27)

    Fixed

    • Compatibility with Magento 2.1

    1.0.5

    (2018-12-11)

    Fixed

    • Error during reindex mst_sorting by cron

    1.0.4

    (2018-12-07)

    Features

    • Show configurable products at top of the list #3

    1.0.3

    (2018-12-06)

    Fixed

    • Error during reindexing due to discount criterion

    1.0.2

    (2018-12-06)

    Fixed

    • Error during reindex sorting index

    1.0.1

    (2018-12-05)

    Improvements

    • Compatibility with M2.1

    Documentation

    • Added module docs