Skip to main content
24 votes

Magento 2 How to add custom sort by option

We can achieve it by using Plugins. Please create following files in your module. app/code/Package/CustomToolbar/etc/di.xml <type name="Magento\Catalog\Model\Config"> <plugin name="...
Sumit Verma's user avatar
9 votes
Accepted

How to sort by position field

You will need to add sort order to search criteria Add \Magento\Framework\Api\SortOrderBuilder $sortOrderBuilder as dependency in constructor. public function getCollection() { $...
Prachi Saxena's user avatar
8 votes
Accepted

Magento 2 : How to remove default sort by options and add custom sort by options?

You need to a custom extension with plugins, I followed this app/code/Company/CustomSort/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Akhilesh Singh's user avatar
8 votes
Accepted

In magento2,Category Sorting Product list: How to remove position from attributes?

quick workaround can be add a condition in theme templates file Magento_Catalog/templates/product/list/toolbar/sorter.phtml like if $key != 'position' then don't add in drop down options : <...
Naveed Asim's user avatar
  • 3,657
6 votes
Accepted

How arrange payment methods order in magento 2 checkout payment section?

Go to Stores > Configuration > Sales > Payment Methods there you find 'Sort Order' field corresponding to all payment methods. So, provide greater number to paypal and lesser number to sagepay to ...
mighty_hk's user avatar
  • 693
6 votes
Accepted

Sorting and sort direction applied together

You can follow the steps describe below to achieve this customization task. I assume you are using a custom theme "Vendor_theme" . step 1) create the file sorter.phtml under /app/design/frontend/...
Pritam Biswas's user avatar
5 votes

Magento sort collection with multiple attributes

Try this : $this->_collection->setOrder([$field1, $field2, ...], 'DESC'); OR Try this : $this->_collection->setOrder('price', 'desc'); $this->_collection->getSelect()->order('...
Ashish Jagnani's user avatar
5 votes

Magento 2 How to add custom sort by option

Step 1: First you should create registration.php Vendor name: Arun Module name: NewSorting Vendor/Modulename/registration.php <?php \Magento\Framework\Component\ComponentRegistrar::register( \...
Arunprabakaran M's user avatar
5 votes

Magento 2 How to add custom sort by option

If you want to use just Create At attribute, you can activate this attribute in admin panel in sorting options. Example: <?php namespace Vendor\Module\Setup; use Magento\Eav\Setup\EavSetup; use ...
iproger's user avatar
  • 73
5 votes

Magento - Unable to set order of collection

To expand on the other answers here, $kitCollection->getSelect()->order('column DESC') works fine, but you can't add more than one column. For instance, $kitCollection->getSelect()->order('...
Tyler V.'s user avatar
  • 2,987
5 votes

How to add custom sort by option filter in tool bar in magento2

I created these custom sort by options: price high - low --> (including all forms of discounts) price low - high --> (including all forms of discounts) name a-z name z-a newest oldest Magento ...
Lez's user avatar
  • 2,947
5 votes
Accepted

Magento product collection override sort order with own order

Implement this answer only when you know the existing list of sort orders applied on the collection, as the below solution will reset the list of all existing sort orders on the collection and reapply ...
nikin's user avatar
  • 1,142
4 votes

Magento2 : How to change sort by option position in sorting options

Yes , Native Three Option position, name, price comes and by default Sort by position is selected Added Size 4th criteria to sort Suppose you want to make Short by Size by default Go to below ...
Manoj Deswal's user avatar
  • 5,805
4 votes

Magento 2 adminhtml custom column sorting ascending and descending

<column name="order_state" class="Foobar\InvoiceOrderStatus\Ui\Component\Listing\Column\Status"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"&...
Prince Patel's user avatar
  • 22.9k
4 votes
Accepted

Magento 2.2.2 - Rename Sort By Options Label

You can change sort by option label using Magento Translations directly through comma-separated value (.csv) file without making any changes in code. For example, your store locale en_US then just ...
Rahul Kachhadiya's user avatar
4 votes

Magento 2 - Product sorting issue on category page using product attribute

Please try following way using custom plugin, so please add plugin code in your custom extension as below /Vendor/Module/etc/frontend/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://...
Aasim Goriya's user avatar
  • 5,454
4 votes

Some Filters not showing on some Categories in Magento 2.4

There maybe a two possibilites: Please check whether the attribute "newest" is assigned to the attribute set of that category. There may not be products available with "newest" ...
Rajesh Selvam's user avatar
3 votes
Accepted

Sorting Cross-Sell Products in Magento 2.1

getCrossSellProductCollection returns instance of Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection This collection implements following method: public function setOrder($attribute,...
isls's user avatar
  • 46
3 votes
Accepted

How to display search results sorted by categories

The reference you are using is not working is because there is no code to sort the products by category. You need to override Mage_CatalogSearch_Block_Result::_getProductCollection() and then add ...
Jaimin Sutariya's user avatar
3 votes

Magento2 sort products and search result by stock availability

Path : Vendor\ModuleName\etc\di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:...
ManiMaran A's user avatar
  • 1,146
3 votes

Sorting custom attribute not working in magento

Please add attribute to select then apply sorting by using order() $collection1 = Mage::getModel('catalog/product')->getCollection(); $collection1->addAttributeToSelect('*'); $...
Nalin Savaliya's user avatar
3 votes

Product List Page Sort by Most View in magento 2.1

If you want to add option in the sort menu then you need to create a plugin as I achieved 1) create di.xml file and the below code <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/...
Mohammad Maheboob's user avatar
3 votes

Sort products by color in the cart in Magento2

You can use the SearchInterface to sort things by a certain value. You will need to edit the Block function getAllItems (if you don't know how to do this i can provide more information , just ask) ...
CompactCode's user avatar
  • 2,477
3 votes

How to convert Magento 2 Sort By Dropdown to Horizontal List

Open your theme /Magento_Catalog/templates/product/list/toolbar/sorter.phtml file and replace your select block with this code below, you may need to copy the magento template file to your theme : &...
Naveed Asim's user avatar
  • 3,657
3 votes

Sorting and sort direction applied together

Create a module with name STech_Sortby by following below steps: Step 1: Create registration.php under app/code/STech/Sortby/registration.php <?php \Magento\Framework\Component\...
Sukumar Gorai's user avatar
3 votes
Accepted

Grouped product (simple product sorting on price) Magento 2

Override public function getAssociatedProducts($product) of this file: vendor/magento/module-grouped-product/Model/Product/Type/Grouped.php in this function you have to remove setPositionOrder() ...
Satish Dubariya's user avatar
3 votes
Accepted

Sorting by product ID

What you need to do is follow this link Magento 2 How to add custom sort by option , override this two files as @LucScu mentioned: \vendor\magento\module-catalog\Block\Product\ProductList\Toolbar.php ...
Ylgen Guxholli's user avatar
3 votes

How to change products sort order in magento 2?

Well, I think there are two ways. Create your own sort option in a module using a plugin. Something like this: Magento 2 How to add custom sort by option. Look at Luca S's answer. I think this person ...
Oscprofessionals's user avatar
3 votes
Accepted

Sort the product collection before load by attribute option in Magento2

You can't sort by attribute options value. You can sort by asc or desc by attirbute using addAttributeToSort(). This is core issue generated in github. You can get reference about that by this below ...
Rohan Hapani's user avatar
  • 17.5k
3 votes

Magento2: I want to show featured product on top of the category and search result

@Purushotam Sharma, If you want to setOrder to collection with two attributes or more then that then you can use the below code in your custom collection: $collection->getSelect()->order(new ...
Rik Patel's user avatar
  • 484

Only top scored, non community-wiki answers of a minimum length are eligible