Hot answers tagged

46 votes
Accepted

Magento - Unable to set order of collection

EAV collections work with attributes, the sorting method is a little different here as well $componentQuantityCollection->addAttributeToSort('sku', 'ASC'); For non-EAV collections use one of the ...
  • 37.4k
25 votes
Accepted

Magento 1.9.1 configurable product attribute sorting

Note: It has been brought to my attention that this solution does not work for Magento 1.9.2. In order to save others wasted time I'd like to point this out at the top of this post. If I develop my ...
25 votes
Accepted

Magento 2 How to add custom sort by option

If you want to use an attribute like created_at that it isn't in admin->stores->(attribute) product, because attributes defined in admin have the setting Sorting in Product Listing = Yes/No, you have ...
  • 2,274
23 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="...
17 votes
Accepted

Need to change my sort order for search results

I found the answer after some intense searching on Stack Overflow all i had to do was add these lines to my layout.xml <catalogsearch_result_index> <reference name="search_result_list"&...
  • 2,185
15 votes

Magento - Unable to set order of collection

You can add sort order like this: $kitCollection->getSelect()->order('related_sku DESC'); More information: http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/...
  • 151
11 votes

Magento 1.9.1 configurable product attribute sorting

Just to add my two cents, the other two answers did well to point me in fix's direction, but I thought I'd attack it at the source rather than the block presentation point. You can achieve the same ...
  • 1,984
11 votes

Shopping cart sorting

We'll need to fix this in 2 parts. The first part is actually tracking which simple products in the cart come from grouped products. The second is the sorting. First for the tracking. We'll add an ...
  • 37.4k
11 votes

How to reset a specific order by column?

The available sorting methods are addOrder(), setOrder(), unshiftOrder(), addAttributeToSort() and getSelect()->order() Only setOrder($field, $dir) is available regardless of collection type and ...
8 votes
Accepted

How can I add a sort by rating?

To sort products by rating you can use the following code, taken from this module: $collection->joinField( 'rating_summary', // alias 'review/review_aggregate', ...
  • 6,500
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:...
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 : <...
  • 3,527
8 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() { $...
7 votes
Accepted

sort products by newest, discount, most sold, reviews" in products list page

for -> Recently Viewed see here for ->Sorting by rating Copy the file app/code/core/Mage/Catalog/Block/Product/List.php to app/code/local/Mage/Catalog/Block/Product/List.php in list.php find ...
  • 1,726
7 votes
Accepted

What factors are used to determine display order when the "Sort By Relevance" option is used while searching in Magento Connect?

I would suppose that search is implemented using MySQL FULLTEXT index. Here is a quote from MySQL official documentation regarding to how that index works: Rows returned are automatically sorted ...
  • 716
6 votes

How to list products in descending order?

Question is tagged CE 1.7.0.2 but this solution is useful for those on 1.9.1.1 so I'm adding it here. We had an opposite problem where we needed to show the cheapest products first when sorted by ...
6 votes

Change default sort order in Manage Products admin

Typical! After hours of searching I make a post...only to find the answer 5 minutes later. Modify the local file app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php and make line 41 read: $...
  • 241
6 votes

How do I list all products in ascending order in Magento?

The reason you got two lists with ascending order is because of PHP sort() function. The default sorting behavior for this function is non-natural ordering, so it gives you unpredictable results. Try ...
  • 2,118
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 ...
  • 675
5 votes
Accepted

How to get recently added sort by option?

To get recently added sort by option open app/code/core/Mage/Catalog/Block/Product/List/toolbar.php and find and replace the below code will be in line 232 if ($this->getCurrentOrder()) { ...
  • 1,726
5 votes
Accepted

Programmatically sort product Collection

easymoden00b,Magento have a magic function addAttributeToSort() which is sort your product Collection on basic of product attribute Format: $ProductCollectionObject->addAttributeToSort('...
  • 76k
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('...
  • 2,967
5 votes
Accepted

Exclude custom options price from sorting

Yes, Magento sorts by the minimum price, which is stored in the price index table and takes required options into account. In the default theme you should actually see "as low as 110 EUR" in the ...
5 votes
Accepted

Cannot sorting joined column in Magento Grid

I have founded the answered after a few days. The solution for this kind of problem is added this function to grid: (overwrite _setCollectionOrder in parent grid class). protected function ...
  • 792
5 votes

product collection sorting by price is not working

Try this add price to collection: $_productCollection->joinAttribute( 'price', 'catalog_product/price', 'entity_id', null, 'left', ...
  • 76k
5 votes
Accepted

How to edit the sorting order of New Products displayed on Magento homepage

Welcome to Magento.SE! This is quite easy to do and will require that you make a module to rewrite the functionality of Mage_Catalog_Block_Product_New. Once you've done that, you need to just make ...
  • 35.6k
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 ...
  • 73
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( \...
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('...
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 by creating a ...
  • 2,737

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