I have created a custom plugin for sorting options for high to low & low to high price. High to low sort works fine but "low to high" sort order not showing correct results.


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <type name="Magento\Catalog\Block\Product\ProductList\Toolbar">
    <plugin name="digital_customsort_block_product_productlist_toolbar" type="Digital\CustomSort\Plugin\Catalog\Block\Product\ProductList\Toolbar" />
    <type name="Magento\Catalog\Model\Config">
        <plugin name="digital_customsort_model_config" type="Digital\CustomSort\Plugin\Catalog\Model\Config" />


//namespace Digital\CustomSort\Plugin\Model;
//class Config extends \Magento\Catalog\Model\Config

namespace Digital\CustomSort\Plugin\Catalog\Model;
use Magento\Catalog\Model\Config as CatalogConfig;

class Config
    public function afterGetAttributeUsedForSortByArray(CatalogConfig $subject, $result)
        $result['low_to_high'] = __('Price - Low To High');
        $result['high_to_low'] = __('Price - High To Low');
        return $result;


 //namespace Digital\CustomSort\Plugin\Block\Product\ProductList;
 //class Toolbar extends \Magento\Catalog\Block\Product\ProductList\Toolbar

namespace Digital\CustomSort\Plugin\Catalog\Block\Product\ProductList;

use Magento\Catalog\Block\Product\ProductList\Toolbar as ProductListToolbar;

class Toolbar
    public function afterSetCollection(ProductListToolbar $subject, $result, $collection)
        switch ($subject->getCurrentOrder()) {
            case 'low_to_high':
                return $result->getCollection()->setOrder('price', 'asc');
            case 'high_to_low':
                return $result->getCollection()->setOrder('price', 'desc');
                return $result;

Your solution is really similar to this


Have you seen this answer? Makes sense to me although some users have said it doesnt work.

Plus it doesnt factor special pricing.

| improve this answer | |
  • I tried this solution but not working. – Shoaib Saleem Jul 22 '19 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.