Hot answers tagged

25 votes

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 ...
LucScu's user avatar
  • 2,322
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="...
Sumit Verma's user avatar
13 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 ...
Denis Spalenza's user avatar
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 ...
Sander Mangel's user avatar
9 votes

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

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="" xsi:...
Akhilesh Singh's user avatar
8 votes

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,637
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 ...
Jayesh Patel's user avatar
  • 2,118
6 votes

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

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 - 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 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 ...
philwinkle's user avatar
  • 35.8k
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 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

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,907
5 votes

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,132
4 votes

Custom Sort order for magento product collection (Sort collection by an array values)

Here is what i have done, Override "vendor/magento/module-catalog/Block/Product/ProductList/Toolbar.php" file to your module "app/code/Namespace/Catalog/Block/Rewrite/Product/ProductList/Toolbar.php" ...
Narayan S's user avatar
  • 594
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,785
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.7k
4 votes

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,424
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

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

Try this code : <? $collection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->addAttributeToSort('name','ASC') // for name ->setPageSize(5000)->...
Arunendra's user avatar
  • 7,436
3 votes

Natural sort for sortby Name

You replaced the collection in the toolbar block, but the list block which is used to display the products still contains the original collection. Since the toolbar adds the sort order, changing the ...
Fabian Schmengler's user avatar
3 votes

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

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="" xsi:noNamespaceSchemaLocation="urn:magento:framework:...
ManiMaran A's user avatar
  • 1,126
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="
Mohammad Maheboob's user avatar

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