Improved Sorting - Getting Started

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

First of all we recommend to check the following link:

How to install the Improved Sorting extension

  1. Backup your store's database and web directory.
  2. Login 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 command php -f bin/magento module:enable Mirasvit_Core Mirasvit_Sorting to enable the extension.
  5. Run command php -f bin/magento setup:upgrade to install the extension.
  6. Run 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 available factors. You can add a Factor by pressing Add New button. You will see then a Ranking factor dialog, which contain basic data:

General information:

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

Configuration:

Depends on data type:

  • Date - Rank products based on Created At/Updated At date;
    • Creation date - when the product was added to the database;
    • Updating date - when the product was updated the last time;
    • Zero point - Number of days the Created At/Updated At date is of influence of the products ranking.

      Note

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

Note

After creating or making changes, make 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 list is empty, magento will use 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, 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 category page;
  • Default for Search - applies sorting criteria by default on the search results page (instead of sort by relevance);
  • Position - position of sorting option in the dropdown on front-end.
  • Conditions - describes logic to sort products. You can use:
    • Catalog attributes - an attribute is visible for sorting, if option Used for Sorting in Product Listing is enabled (Stores > Attributes > Product);
    • Ranking factors - allows choosing one of the Ranking Factors;
    • ASC (A-Z, 0-9)/DESC (Z-A, 9-0) - allows sorting from smallest to largest/ from largest to smallest;
    • Weight - allows increasing the impact of the factor in a particular rule, set the value within 1 - 100;
    • Limit - sets the maximum number of products for which this weight will be applied;
  • Add New Sub Condition button - allows adding several criteria and set 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 make 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 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 following 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 URL. Does not affect anything else.

    Sorting for Widgets

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

    How to add new widget

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

    New Widget

    Debugging

    To check the product position in the backend, use the Preview button when creating 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 - Improved Sorting

    Usage: php -f bin/magento [options]

    • mirasvit:sorting:reindex - reindex extension indexes. Same as native Magento 2 command: indexer:reindex mst_sorting

    How To - Improved Sorting

    Contents

    How can I translate sorting label to different languages

    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 required sorting criteria for this category.

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

    How to upgrade Improved Sorting extension

    To upgrade the extension follow these steps:

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

      Note

      In some cases the command above is not applicable, it's not possible to update just current module, or you just need to upgrade all Mirasvit modules in a bundle. In this case command above will have no effect.

      Run instead composer update mirasvit/* command. It will update all Mirasvit modules, installed on your store.

    4. Run command php -f bin/magento setup:upgrade to install updates.
    5. Run 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 Improved Sorting extension

    Temporarily Disable

    To temporarily disable the extension please follow these steps:

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

    Removing the Extension

    To uninstall the extension please follow these steps:

    1. Login 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. Login in to the Magento back-end and refresh the store cache (if enabled).

    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