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="...
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()
{
$...
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 :
<...
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 ...
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/...
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
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 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 ...
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('...
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 ...
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 ...
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 ...
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"&...
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 ...
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://...
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" ...
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,...
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 ...
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:...
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('*');
$...
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/...
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)
...
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 :
&...
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\...
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() ...
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
...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sorting × 378magento2 × 100
magento-1.9 × 83
category × 43
collection × 41
product-collection × 37
product-list × 32
attributes × 25
product × 24
product-sorting × 24
magento-1.8 × 20
sort × 19
grid × 17
category-products × 17
magento2.3 × 16
magento-1.7 × 16
product-attribute × 15
filter × 14
admin × 13
configurable-product × 12
catalog × 12
products × 12
price × 11
magento-enterprise × 11
magento-1 × 10