8 votes
Accepted

Magento 2 - Get Collection using custom product Ids and also sort them as the same order as product Ids passed

You just need to add order along with your addAttributeToFilter $collection->addAttributeToFilter('entity_id', array('in' => $productIdsarray )); $collection->getSelect()->order(new \...
user avatar
4 votes
Accepted

Magento 2.2 - custom product sorting issue

In your stock condition just remove alias name csi and try, It's work for me. if ($this->getCurrentOrder() == 'stock') { $this->_collection->getSelect() ->joinLeft( ...
user avatar
  • 164
4 votes
Accepted

Magento2: How to remove default sort option from category page?

You can set Used for Sorting in Product Listing to No for the attributes which you want to remove from sorting options on PLP. Magento Admin -> stores -> Attributes -> Products -> select Attribute ...
user avatar
3 votes

Sort by product name not working as expected

That is lexicographic sorting which means basically the language treats the variables as strings and compares character by character "200" is greater than "19999" because '2' is greater than '1'. So ...
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 ...
user avatar
3 votes

Change 'Sort by Position' text to 'Sort by New' Magento 2.2.6

di.xml override Magento\Catalog\Model\Config.php app\code\[Vendor]\[Module]\etc\frontend\di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
user avatar
3 votes

Desperately need Help with a task for a test in Magento 1.9.3

This should solve your problem. app/design/frontend/rwd/default/template/atwix/cmsattr/list.phtml: You will need to add two new buttons so you can order ascending and descending. These buttons are ...
user avatar
  • 2,471
3 votes
Accepted

Getting the wrong chinese string in search query result!! Magento 1

app/design/frontend/[Magento theme Folder]/template/catalog/product/list/toolbar.phtml Goto: 82 Line or search getOrderUrl($_key, 'asc') ?> from <label><?php echo $this->__('Sort By') ...
user avatar
  • 1,883
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) ...
user avatar
  • 2,377
2 votes

How to Sort New Products at Home by Product Name

Please update bellow function from: protected function _getProductCollection() { switch ($this->getDisplayType()) { case self::DISPLAY_TYPE_NEW_PRODUCTS: $...
user avatar
  • 9,552
2 votes
Accepted

How to Sort New Products at Home by Product Name

Take class Mage_Catalog_Block_Product_Widget_New in local folder or extend it with your own Find the below function protected function _getProductCollection() { switch ($this->...
user avatar
2 votes
Accepted

Magento 2 filtering product collection and sorting

You can sort it by give values if ($subject->getCurrentOrder() == 'CustomAttribute') { $values=array(1); $collection->setOrder('position', 'asc'); $collection->...
user avatar
  • 32.1k
2 votes

Magento 2.2 - Sorting product in category page by position not working

It is Magento2.2 default bug. Please follow this to solve your problem. Create etc/di.xml file. <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
user avatar
2 votes

how to remove white space from product name during custom product collection?

Untested code: $categoryProducts = $category->getProductCollection() ->addAttributeToSelect('*') ->addExpressionAttributeToSelect( 'trim_name', 'TRIM({{name}...
user avatar
  • 196k
2 votes
Accepted

Remove option "Relevance" from sort by

To remove relevance sort order in searching you can rewrite below class app/code/core/Mage/CatalogSearch/Block/Result.php Mage_CatalogSearch_Block_Result in your custom module and rewrite this ...
user avatar
2 votes

Magento 1.9: Change product order and direction on load?

You can change the direction from layout XML of your theme. Below is the code of the local.xml file for your reference. <?xml version="1.0"?> <layout version="0.1.0"> <!-- Change ...
user avatar
  • 4,705
2 votes

Magento2 - catalog product listing collection sort by price with dynamic price calculation

I assume, In Category page you are trying to sort by the price and not getting the correct order while you want your prices to be displayed as well as used in sorting. etc/frontend/di.xml <?xml ...
user avatar
2 votes

How to print Product collection mysql query in magento2

Try this type code that is example of how to print mysql query. <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productCollections = $objectManager->...
user avatar
2 votes
Accepted

How to print Product collection mysql query in magento2

Let's say you have a product collection like this: //$collection is instance of Magento\Catalog\Model\ResourceModel\Product\Collection $collection->addAttributeToSelect('*'); $collection->...
user avatar
  • 8,888
2 votes

Magento 2 how to use elasticsearch for custom indexer? Custom sort stops working after enabling elasticsearch

Custom Sort with ElasticSearch in Magento issue can be fixed by following these simple steps: Navigate to Stores->Attributes->Product in Admin. Add New Attribute. In Properties->Attribute Properties: ...
user avatar
2 votes
Accepted

Magento 2.3 Natural Sort Order for Numeric Attributes / Sort Order Wrong

By default, if you don't specify it in the attribute, text attributes allow different types of characters: Since strings are allowed, Magento's sort query is as follows: ORDER BY custom_order ASC, `e`....
user avatar
  • 1,183
1 vote
Accepted

Sorting attributes are not working Magento 2.3

This will help you in some way as you suggest its working in your local but not on a server so better to go through points. If an issue from the code level then it may not help you further. Find ...
user avatar
  • 3,582
1 vote

Magento 2: How to sort product on Category page by entity id in desc order?

Easiest and cleanest solution would be creating an "afterPlugin" on \Magento\Catalog\Model\Config\Source\ListSort::toOptionArray and adding $options[] = ['label' => __('Entity ID'), 'value' => '...
user avatar
1 vote
Accepted

Magento 2 What is the different between setDefaultOrder and SetSortBy in layout xml?

Not sure where you've got one of those snippets from https://www.customerparadigm.com/changing-default-product-sorting-in-magento-2/ app/design/frontend/{{Vendor_Namespace}}/{{Theme_Name}}/...
user avatar
1 vote

How to print Product collection mysql query in magento2

In a simple way, echo your collection with getSelect function. Here it is echo $collection->getSelect();
user avatar
  • 1,779
1 vote

Change 'Sort by Position' text to 'Sort by New' Magento 2.2.6

Create plugin <type name="Magento\Catalog\Model\Config"> <plugin name="custom_sortby_text" type="Vendor\Module\Plugin\Catalog\Model\Config" /> </type> config.php ...
user avatar
  • 1,038
1 vote

Change 'Sort by Position' text to 'Sort by New' Magento 2.2.6

Well, since they're both English, I don't think that approach will work. You need to make some changes to the source code. In your module, in the file module_dir/Model/Config.php: <?php ...
user avatar
  • 331
1 vote
Accepted

How to Shuffle Product Collection in Magento 2?

Try this: $collection = $this->_productCollectionFactory->create(); $collection->addAttributeToSelect('*'); $collection->addCategoriesFilter(['in' => $categories]); $collection->...
user avatar
  • 16.6k
1 vote

Remove option "Relevance" from sort by

Sort options are set in Mage_CatalogSearch_Block_Result::setListOrders() To override this you can add something like this to your local.xml <catalogsearch_result_index> <reference name="...
user avatar
  • 11.5k
1 vote

Magento2 : How can to get product collection by sorting with stock status i.e Asc,Decs

Use below code to your class to filter out of stock product /** * @var \Magento\CatalogInventory\Helper\Stock */ protected $_stockFilter; protected $collectionFactory; on class constructor ...
user avatar
  • 2,493

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