Magento 2 sort options Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm...

How does the math work when buying airline miles?

How to ternary Plot3D a function

Test print coming out spongy

Is openssl rand command cryptographically secure?

License to disallow distribution in closed source software, but allow exceptions made by owner?

A proverb that is used to imply that you have unexpectedly faced a big problem

New Order #6: Easter Egg

Why is a lens darker than other ones when applying the same settings?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

What is the "studentd" process?

How can a team of shapeshifters communicate?

What does 丫 mean? 丫是什么意思?

How to write capital alpha?

Co-worker has annoying ringtone

What does Turing mean by this statement?

Flight departed from the gate 5 min before scheduled departure time. Refund options

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

Can two person see the same photon?

A `coordinate` command ignored

NERDTreeMenu Remapping

Special flights

Is there public access to the Meteor Crater in Arizona?

Does the Mueller report show a conspiracy between Russia and the Trump Campaign?

If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?



Magento 2 sort options



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Magento 2 add Sort By Best Sellers Option on category products litsing pagemagento2 how to sort order of product by priceMagento 2 Sort by New Products and Most View ProductUnit Test for overwrite collection class in magento2Magento model extension experiment, return: “class does not exist”Magento2 override admin js filemain.CRITICAL: Plugin class doesn't existMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formCategory order does not work, always sort by the entity_id descMagento 2.3 Can't view module's front end page output?Magento 2 get custom attribute of a single product inside a pluginMagento 2 How to remove price filter from category if module is enable?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I used Magento 2 add Sort By Best Sellers Option on category products litsing page and Magento 2 Sort by New Products and Most View Product for sorting options. now I want to add price (high to low) and remove name (default option) and direction switcher. Could anyone help me please?



here is my code :



CompanyModuleModelConfig



class Config extends MagentoCatalogModelConfig
{
public function getAttributeUsedForSortByArray()
{
$options = ['mostviewed' => __('Most Viewed'), 'newest' => __('Newest'), 'bestseller' => __('Best Seller'), 'price' => __('Price - Low To Highا');
foreach ($this->getAttributesUsedForSortBy() as $attribute) {
/* @var $attribute MagentoEavModelEntityAttributeAbstractAttribute */
$options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
}

return $options;
}
}


CompanyModuleBlockProductProductListToolbar



class Toolbar extends MagentoCatalogBlockProductProductListToolbar
{
public function setCollection($collection)
{
if($this->getCurrentOrder()=="bestseller")
{
$collection->getSelect()->joinLeft(
'sales_order_item',
'e.entity_id = sales_order_item.product_id',
array('qty_ordered'=>'SUM(sales_order_item.qty_ordered)'))
->group('e.entity_id')
->order('qty_ordered '.$this->getCurrentDirectionReverse());
}
if($this->getCurrentOrder() == "newest")
{
$collection->getSelect()
->order('created_at ' . $this->getCurrentDirectionReverse());
}
if($this->getCurrentOrder() == "mostviewed")
{
$collection->getSelect()->joinLeft(
'report_event',
'e.entity_id = report_event.object_id',
array('view_count' => 'COUNT(report_event.event_id)'))
->group('e.entity_id')
->order('view_count ' . $this->getCurrentDirectionReverse());
}

$this->_collection = $collection;

$this->_collection->setCurPage($this->getCurrentPage());

$limit = (int)$this->getLimit();
if ($limit) {
$this->_collection->setPageSize($limit);
}
if ($this->getCurrentOrder()) {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
return $this;
}

public function getCurrentDirectionReverse() {
if ($this->getCurrentDirection() == 'asc') {
return 'desc';
} elseif ($this->getCurrentDirection() == 'desc') {
return 'asc';
} else {
return $this->getCurrentDirection();
}
}

}









share|improve this question














bumped to the homepage by Community 6 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















    0















    I used Magento 2 add Sort By Best Sellers Option on category products litsing page and Magento 2 Sort by New Products and Most View Product for sorting options. now I want to add price (high to low) and remove name (default option) and direction switcher. Could anyone help me please?



    here is my code :



    CompanyModuleModelConfig



    class Config extends MagentoCatalogModelConfig
    {
    public function getAttributeUsedForSortByArray()
    {
    $options = ['mostviewed' => __('Most Viewed'), 'newest' => __('Newest'), 'bestseller' => __('Best Seller'), 'price' => __('Price - Low To Highا');
    foreach ($this->getAttributesUsedForSortBy() as $attribute) {
    /* @var $attribute MagentoEavModelEntityAttributeAbstractAttribute */
    $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
    }

    return $options;
    }
    }


    CompanyModuleBlockProductProductListToolbar



    class Toolbar extends MagentoCatalogBlockProductProductListToolbar
    {
    public function setCollection($collection)
    {
    if($this->getCurrentOrder()=="bestseller")
    {
    $collection->getSelect()->joinLeft(
    'sales_order_item',
    'e.entity_id = sales_order_item.product_id',
    array('qty_ordered'=>'SUM(sales_order_item.qty_ordered)'))
    ->group('e.entity_id')
    ->order('qty_ordered '.$this->getCurrentDirectionReverse());
    }
    if($this->getCurrentOrder() == "newest")
    {
    $collection->getSelect()
    ->order('created_at ' . $this->getCurrentDirectionReverse());
    }
    if($this->getCurrentOrder() == "mostviewed")
    {
    $collection->getSelect()->joinLeft(
    'report_event',
    'e.entity_id = report_event.object_id',
    array('view_count' => 'COUNT(report_event.event_id)'))
    ->group('e.entity_id')
    ->order('view_count ' . $this->getCurrentDirectionReverse());
    }

    $this->_collection = $collection;

    $this->_collection->setCurPage($this->getCurrentPage());

    $limit = (int)$this->getLimit();
    if ($limit) {
    $this->_collection->setPageSize($limit);
    }
    if ($this->getCurrentOrder()) {
    $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
    }
    return $this;
    }

    public function getCurrentDirectionReverse() {
    if ($this->getCurrentDirection() == 'asc') {
    return 'desc';
    } elseif ($this->getCurrentDirection() == 'desc') {
    return 'asc';
    } else {
    return $this->getCurrentDirection();
    }
    }

    }









    share|improve this question














    bumped to the homepage by Community 6 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0


      1






      I used Magento 2 add Sort By Best Sellers Option on category products litsing page and Magento 2 Sort by New Products and Most View Product for sorting options. now I want to add price (high to low) and remove name (default option) and direction switcher. Could anyone help me please?



      here is my code :



      CompanyModuleModelConfig



      class Config extends MagentoCatalogModelConfig
      {
      public function getAttributeUsedForSortByArray()
      {
      $options = ['mostviewed' => __('Most Viewed'), 'newest' => __('Newest'), 'bestseller' => __('Best Seller'), 'price' => __('Price - Low To Highا');
      foreach ($this->getAttributesUsedForSortBy() as $attribute) {
      /* @var $attribute MagentoEavModelEntityAttributeAbstractAttribute */
      $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
      }

      return $options;
      }
      }


      CompanyModuleBlockProductProductListToolbar



      class Toolbar extends MagentoCatalogBlockProductProductListToolbar
      {
      public function setCollection($collection)
      {
      if($this->getCurrentOrder()=="bestseller")
      {
      $collection->getSelect()->joinLeft(
      'sales_order_item',
      'e.entity_id = sales_order_item.product_id',
      array('qty_ordered'=>'SUM(sales_order_item.qty_ordered)'))
      ->group('e.entity_id')
      ->order('qty_ordered '.$this->getCurrentDirectionReverse());
      }
      if($this->getCurrentOrder() == "newest")
      {
      $collection->getSelect()
      ->order('created_at ' . $this->getCurrentDirectionReverse());
      }
      if($this->getCurrentOrder() == "mostviewed")
      {
      $collection->getSelect()->joinLeft(
      'report_event',
      'e.entity_id = report_event.object_id',
      array('view_count' => 'COUNT(report_event.event_id)'))
      ->group('e.entity_id')
      ->order('view_count ' . $this->getCurrentDirectionReverse());
      }

      $this->_collection = $collection;

      $this->_collection->setCurPage($this->getCurrentPage());

      $limit = (int)$this->getLimit();
      if ($limit) {
      $this->_collection->setPageSize($limit);
      }
      if ($this->getCurrentOrder()) {
      $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
      }
      return $this;
      }

      public function getCurrentDirectionReverse() {
      if ($this->getCurrentDirection() == 'asc') {
      return 'desc';
      } elseif ($this->getCurrentDirection() == 'desc') {
      return 'asc';
      } else {
      return $this->getCurrentDirection();
      }
      }

      }









      share|improve this question














      I used Magento 2 add Sort By Best Sellers Option on category products litsing page and Magento 2 Sort by New Products and Most View Product for sorting options. now I want to add price (high to low) and remove name (default option) and direction switcher. Could anyone help me please?



      here is my code :



      CompanyModuleModelConfig



      class Config extends MagentoCatalogModelConfig
      {
      public function getAttributeUsedForSortByArray()
      {
      $options = ['mostviewed' => __('Most Viewed'), 'newest' => __('Newest'), 'bestseller' => __('Best Seller'), 'price' => __('Price - Low To Highا');
      foreach ($this->getAttributesUsedForSortBy() as $attribute) {
      /* @var $attribute MagentoEavModelEntityAttributeAbstractAttribute */
      $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
      }

      return $options;
      }
      }


      CompanyModuleBlockProductProductListToolbar



      class Toolbar extends MagentoCatalogBlockProductProductListToolbar
      {
      public function setCollection($collection)
      {
      if($this->getCurrentOrder()=="bestseller")
      {
      $collection->getSelect()->joinLeft(
      'sales_order_item',
      'e.entity_id = sales_order_item.product_id',
      array('qty_ordered'=>'SUM(sales_order_item.qty_ordered)'))
      ->group('e.entity_id')
      ->order('qty_ordered '.$this->getCurrentDirectionReverse());
      }
      if($this->getCurrentOrder() == "newest")
      {
      $collection->getSelect()
      ->order('created_at ' . $this->getCurrentDirectionReverse());
      }
      if($this->getCurrentOrder() == "mostviewed")
      {
      $collection->getSelect()->joinLeft(
      'report_event',
      'e.entity_id = report_event.object_id',
      array('view_count' => 'COUNT(report_event.event_id)'))
      ->group('e.entity_id')
      ->order('view_count ' . $this->getCurrentDirectionReverse());
      }

      $this->_collection = $collection;

      $this->_collection->setCurPage($this->getCurrentPage());

      $limit = (int)$this->getLimit();
      if ($limit) {
      $this->_collection->setPageSize($limit);
      }
      if ($this->getCurrentOrder()) {
      $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
      }
      return $this;
      }

      public function getCurrentDirectionReverse() {
      if ($this->getCurrentDirection() == 'asc') {
      return 'desc';
      } elseif ($this->getCurrentDirection() == 'desc') {
      return 'asc';
      } else {
      return $this->getCurrentDirection();
      }
      }

      }






      magento2 magento2.2






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 2 '18 at 17:44









      BenyoBenyo

      187




      187





      bumped to the homepage by Community 6 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 6 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          For price high to low, add a condition like this in your CompanyModuleBlockProductProductListToolbar file and setCollection function:



          if($this->getCurrentOrder()=="high_to_low"){
          {
          $this->_collection->setOrder('price', 'desc');
          }
          if($this->getCurrentOrder()=="low_to_high"){
          {
          $this->_collection->setOrder('price', 'asc');
          }


          and you should have a plugin to override config and it should look like this:



          CompanyModulePluginCatalogModel



          <?php
          namespace CompanyModulePluginCatalogModel;

          class Config
          {
          public function afterGetAttributeUsedForSortByArray(
          MagentoCatalogModelConfig $catalogConfig,
          $options
          ) {
          //Remove specific default sorting options(if require)
          unset($options['position']);
          unset($options['name']);
          unset($options['price']);

          //New sorting options
          $newOption['mostviewed'] = __('Most Viewed');
          $newOption['newest'] = __('Newest');
          $newOption['bestseller'] = __('Best Seller');
          $newOption['high_to_low'] = __('Price - High To Low');
          $newOption['low_to_high'] = __('Price - Low To High');

          //Merge default sorting options with new options
          $options = array_merge($newOption, $options);

          return $options;
          }

          }


          Since we have a plugin, we need to add it in the di.xml file like this under etc/di.xml



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCatalogBlockProductProductListToolbar" type="CompanyModuleBlockProductProductListToolbar" />
          <type name="MagentoCatalogModelConfig">
          <plugin name="Company_CustomSorting_model_config" type="CompanyModulePluginCatalogModelConfig" />
          </type>
          </config>


          To remove the direction switcher, you can remove it using CSS/jQuery that should be simple to select the div element and add display none class in css or add remove jquery function.



          I hope this helps.






          share|improve this answer
























          • thanks @Gideon. I removed name option by your code but price (High to Low) didn't sort correctly. I use default price for Low to High but what can i do for High to Low?!

            – Benyo
            Jul 3 '18 at 11:27











          • sorry. i upvoted your answer but i don't have enough reputation yet

            – Benyo
            Jul 3 '18 at 11:40











          • High to low and low to high is working for me. Please check my Toolbar file here: gist.github.com/GideonBabu/143ad54de27ea7d3997e294fea14b498

            – Gideon
            Jul 3 '18 at 12:35











          • thanks @Gideon. i found a solution here : magento.stackexchange.com/questions/149125/…

            – Benyo
            Jul 3 '18 at 13:23













          • @Benyo I am glad you got the solution.

            – Gideon
            Jul 3 '18 at 13:37












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f232083%2fmagento-2-sort-options%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          For price high to low, add a condition like this in your CompanyModuleBlockProductProductListToolbar file and setCollection function:



          if($this->getCurrentOrder()=="high_to_low"){
          {
          $this->_collection->setOrder('price', 'desc');
          }
          if($this->getCurrentOrder()=="low_to_high"){
          {
          $this->_collection->setOrder('price', 'asc');
          }


          and you should have a plugin to override config and it should look like this:



          CompanyModulePluginCatalogModel



          <?php
          namespace CompanyModulePluginCatalogModel;

          class Config
          {
          public function afterGetAttributeUsedForSortByArray(
          MagentoCatalogModelConfig $catalogConfig,
          $options
          ) {
          //Remove specific default sorting options(if require)
          unset($options['position']);
          unset($options['name']);
          unset($options['price']);

          //New sorting options
          $newOption['mostviewed'] = __('Most Viewed');
          $newOption['newest'] = __('Newest');
          $newOption['bestseller'] = __('Best Seller');
          $newOption['high_to_low'] = __('Price - High To Low');
          $newOption['low_to_high'] = __('Price - Low To High');

          //Merge default sorting options with new options
          $options = array_merge($newOption, $options);

          return $options;
          }

          }


          Since we have a plugin, we need to add it in the di.xml file like this under etc/di.xml



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCatalogBlockProductProductListToolbar" type="CompanyModuleBlockProductProductListToolbar" />
          <type name="MagentoCatalogModelConfig">
          <plugin name="Company_CustomSorting_model_config" type="CompanyModulePluginCatalogModelConfig" />
          </type>
          </config>


          To remove the direction switcher, you can remove it using CSS/jQuery that should be simple to select the div element and add display none class in css or add remove jquery function.



          I hope this helps.






          share|improve this answer
























          • thanks @Gideon. I removed name option by your code but price (High to Low) didn't sort correctly. I use default price for Low to High but what can i do for High to Low?!

            – Benyo
            Jul 3 '18 at 11:27











          • sorry. i upvoted your answer but i don't have enough reputation yet

            – Benyo
            Jul 3 '18 at 11:40











          • High to low and low to high is working for me. Please check my Toolbar file here: gist.github.com/GideonBabu/143ad54de27ea7d3997e294fea14b498

            – Gideon
            Jul 3 '18 at 12:35











          • thanks @Gideon. i found a solution here : magento.stackexchange.com/questions/149125/…

            – Benyo
            Jul 3 '18 at 13:23













          • @Benyo I am glad you got the solution.

            – Gideon
            Jul 3 '18 at 13:37
















          0














          For price high to low, add a condition like this in your CompanyModuleBlockProductProductListToolbar file and setCollection function:



          if($this->getCurrentOrder()=="high_to_low"){
          {
          $this->_collection->setOrder('price', 'desc');
          }
          if($this->getCurrentOrder()=="low_to_high"){
          {
          $this->_collection->setOrder('price', 'asc');
          }


          and you should have a plugin to override config and it should look like this:



          CompanyModulePluginCatalogModel



          <?php
          namespace CompanyModulePluginCatalogModel;

          class Config
          {
          public function afterGetAttributeUsedForSortByArray(
          MagentoCatalogModelConfig $catalogConfig,
          $options
          ) {
          //Remove specific default sorting options(if require)
          unset($options['position']);
          unset($options['name']);
          unset($options['price']);

          //New sorting options
          $newOption['mostviewed'] = __('Most Viewed');
          $newOption['newest'] = __('Newest');
          $newOption['bestseller'] = __('Best Seller');
          $newOption['high_to_low'] = __('Price - High To Low');
          $newOption['low_to_high'] = __('Price - Low To High');

          //Merge default sorting options with new options
          $options = array_merge($newOption, $options);

          return $options;
          }

          }


          Since we have a plugin, we need to add it in the di.xml file like this under etc/di.xml



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCatalogBlockProductProductListToolbar" type="CompanyModuleBlockProductProductListToolbar" />
          <type name="MagentoCatalogModelConfig">
          <plugin name="Company_CustomSorting_model_config" type="CompanyModulePluginCatalogModelConfig" />
          </type>
          </config>


          To remove the direction switcher, you can remove it using CSS/jQuery that should be simple to select the div element and add display none class in css or add remove jquery function.



          I hope this helps.






          share|improve this answer
























          • thanks @Gideon. I removed name option by your code but price (High to Low) didn't sort correctly. I use default price for Low to High but what can i do for High to Low?!

            – Benyo
            Jul 3 '18 at 11:27











          • sorry. i upvoted your answer but i don't have enough reputation yet

            – Benyo
            Jul 3 '18 at 11:40











          • High to low and low to high is working for me. Please check my Toolbar file here: gist.github.com/GideonBabu/143ad54de27ea7d3997e294fea14b498

            – Gideon
            Jul 3 '18 at 12:35











          • thanks @Gideon. i found a solution here : magento.stackexchange.com/questions/149125/…

            – Benyo
            Jul 3 '18 at 13:23













          • @Benyo I am glad you got the solution.

            – Gideon
            Jul 3 '18 at 13:37














          0












          0








          0







          For price high to low, add a condition like this in your CompanyModuleBlockProductProductListToolbar file and setCollection function:



          if($this->getCurrentOrder()=="high_to_low"){
          {
          $this->_collection->setOrder('price', 'desc');
          }
          if($this->getCurrentOrder()=="low_to_high"){
          {
          $this->_collection->setOrder('price', 'asc');
          }


          and you should have a plugin to override config and it should look like this:



          CompanyModulePluginCatalogModel



          <?php
          namespace CompanyModulePluginCatalogModel;

          class Config
          {
          public function afterGetAttributeUsedForSortByArray(
          MagentoCatalogModelConfig $catalogConfig,
          $options
          ) {
          //Remove specific default sorting options(if require)
          unset($options['position']);
          unset($options['name']);
          unset($options['price']);

          //New sorting options
          $newOption['mostviewed'] = __('Most Viewed');
          $newOption['newest'] = __('Newest');
          $newOption['bestseller'] = __('Best Seller');
          $newOption['high_to_low'] = __('Price - High To Low');
          $newOption['low_to_high'] = __('Price - Low To High');

          //Merge default sorting options with new options
          $options = array_merge($newOption, $options);

          return $options;
          }

          }


          Since we have a plugin, we need to add it in the di.xml file like this under etc/di.xml



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCatalogBlockProductProductListToolbar" type="CompanyModuleBlockProductProductListToolbar" />
          <type name="MagentoCatalogModelConfig">
          <plugin name="Company_CustomSorting_model_config" type="CompanyModulePluginCatalogModelConfig" />
          </type>
          </config>


          To remove the direction switcher, you can remove it using CSS/jQuery that should be simple to select the div element and add display none class in css or add remove jquery function.



          I hope this helps.






          share|improve this answer













          For price high to low, add a condition like this in your CompanyModuleBlockProductProductListToolbar file and setCollection function:



          if($this->getCurrentOrder()=="high_to_low"){
          {
          $this->_collection->setOrder('price', 'desc');
          }
          if($this->getCurrentOrder()=="low_to_high"){
          {
          $this->_collection->setOrder('price', 'asc');
          }


          and you should have a plugin to override config and it should look like this:



          CompanyModulePluginCatalogModel



          <?php
          namespace CompanyModulePluginCatalogModel;

          class Config
          {
          public function afterGetAttributeUsedForSortByArray(
          MagentoCatalogModelConfig $catalogConfig,
          $options
          ) {
          //Remove specific default sorting options(if require)
          unset($options['position']);
          unset($options['name']);
          unset($options['price']);

          //New sorting options
          $newOption['mostviewed'] = __('Most Viewed');
          $newOption['newest'] = __('Newest');
          $newOption['bestseller'] = __('Best Seller');
          $newOption['high_to_low'] = __('Price - High To Low');
          $newOption['low_to_high'] = __('Price - Low To High');

          //Merge default sorting options with new options
          $options = array_merge($newOption, $options);

          return $options;
          }

          }


          Since we have a plugin, we need to add it in the di.xml file like this under etc/di.xml



          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="MagentoCatalogBlockProductProductListToolbar" type="CompanyModuleBlockProductProductListToolbar" />
          <type name="MagentoCatalogModelConfig">
          <plugin name="Company_CustomSorting_model_config" type="CompanyModulePluginCatalogModelConfig" />
          </type>
          </config>


          To remove the direction switcher, you can remove it using CSS/jQuery that should be simple to select the div element and add display none class in css or add remove jquery function.



          I hope this helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 3 '18 at 6:25









          GideonGideon

          305316




          305316













          • thanks @Gideon. I removed name option by your code but price (High to Low) didn't sort correctly. I use default price for Low to High but what can i do for High to Low?!

            – Benyo
            Jul 3 '18 at 11:27











          • sorry. i upvoted your answer but i don't have enough reputation yet

            – Benyo
            Jul 3 '18 at 11:40











          • High to low and low to high is working for me. Please check my Toolbar file here: gist.github.com/GideonBabu/143ad54de27ea7d3997e294fea14b498

            – Gideon
            Jul 3 '18 at 12:35











          • thanks @Gideon. i found a solution here : magento.stackexchange.com/questions/149125/…

            – Benyo
            Jul 3 '18 at 13:23













          • @Benyo I am glad you got the solution.

            – Gideon
            Jul 3 '18 at 13:37



















          • thanks @Gideon. I removed name option by your code but price (High to Low) didn't sort correctly. I use default price for Low to High but what can i do for High to Low?!

            – Benyo
            Jul 3 '18 at 11:27











          • sorry. i upvoted your answer but i don't have enough reputation yet

            – Benyo
            Jul 3 '18 at 11:40











          • High to low and low to high is working for me. Please check my Toolbar file here: gist.github.com/GideonBabu/143ad54de27ea7d3997e294fea14b498

            – Gideon
            Jul 3 '18 at 12:35











          • thanks @Gideon. i found a solution here : magento.stackexchange.com/questions/149125/…

            – Benyo
            Jul 3 '18 at 13:23













          • @Benyo I am glad you got the solution.

            – Gideon
            Jul 3 '18 at 13:37

















          thanks @Gideon. I removed name option by your code but price (High to Low) didn't sort correctly. I use default price for Low to High but what can i do for High to Low?!

          – Benyo
          Jul 3 '18 at 11:27





          thanks @Gideon. I removed name option by your code but price (High to Low) didn't sort correctly. I use default price for Low to High but what can i do for High to Low?!

          – Benyo
          Jul 3 '18 at 11:27













          sorry. i upvoted your answer but i don't have enough reputation yet

          – Benyo
          Jul 3 '18 at 11:40





          sorry. i upvoted your answer but i don't have enough reputation yet

          – Benyo
          Jul 3 '18 at 11:40













          High to low and low to high is working for me. Please check my Toolbar file here: gist.github.com/GideonBabu/143ad54de27ea7d3997e294fea14b498

          – Gideon
          Jul 3 '18 at 12:35





          High to low and low to high is working for me. Please check my Toolbar file here: gist.github.com/GideonBabu/143ad54de27ea7d3997e294fea14b498

          – Gideon
          Jul 3 '18 at 12:35













          thanks @Gideon. i found a solution here : magento.stackexchange.com/questions/149125/…

          – Benyo
          Jul 3 '18 at 13:23







          thanks @Gideon. i found a solution here : magento.stackexchange.com/questions/149125/…

          – Benyo
          Jul 3 '18 at 13:23















          @Benyo I am glad you got the solution.

          – Gideon
          Jul 3 '18 at 13:37





          @Benyo I am glad you got the solution.

          – Gideon
          Jul 3 '18 at 13:37


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f232083%2fmagento-2-sort-options%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

          How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

          夢乃愛華...