Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Magento 2: Product sorting high to low and low to high
namespace Company\Module\Block\Product\ProductList;
class Toolbar extends \Magento\Catalog\Block\Product\ProductList\Toolbar
public function setCollection($collection) {
$this->_collection = $collection;
// we need to set pagination only if passed value integer and more that 0
$limit = (int)$this->getLimit();
if ($limit) {
if ($this->getCurrentOrder()) {
switch ($this->getCurrentOrder()) {
case 'high_to_low':
$this->_collection->setOrder('price', 'desc');
case 'low_to_high':
$this->_collection->setOrder('price', 'asc');
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
return $this;

This comment has been minimized.

Copy link

@vikasmehar vikasmehar commented Mar 5, 2020

This is not working with elastic search. Can you please let me know how we can do same with elastic search. I am getting msg We can't find products matching the selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment