This can be done using Plugin
Create the following files in your module: (Assuming you have your own module registered already)
Create your Plugin under Vendor/Modulename/etc/di.xml
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">
<type name="Magento\Catalog\Model\Config">
<plugin name="Vendor_Modulename::addCustomOptions" type="Vendor\Modulename\Plugin\Model\Config" />
</type>
<type name="Magento\Catalog\Block\Product\ProductList\Toolbar">
<plugin name="Vendor::addPriceDescendingFilterInToolbar" type="Vendor\Modulename\Plugin\Product\ProductList\Toolbar" />
</type>
Then create a config.php under namespace Vendor/Modulename/Plugin/Model/Config.php
and put this code:
<?php
namespace Vendor\Modulename\Plugin\Model;
use Magento\Store\Model\StoreManagerInterface;
class Config {
protected $_storeManager;
public function __construct(
StoreManagerInterface $storeManager
) {
$this->_storeManager = $storeManager;
}
public function afterGetAttributeUsedForSortByArray(\Magento\Catalog\Model\Config $catalogConfig, $options)
{
$store = $this->_storeManager->getStore();
$currencySymbol = $store->getCurrentCurrency()->getCurrencySymbol();
// Remove specific default sorting options
$default_options = [];
$default_options['name'] = $options['name'];
//New sorting options
$customOption['price_pcs'] = __( ' Price customSorting' );
//Merge default sorting options with custom options
$options = array_merge($customOption, $options);
return $options;
}
}
Then override the Toolbar.php ***Vendor/Modulename/Plugin/Product/ProductList/Toolbar.php
use this code
<?php
namespace Vendor\Modulename\Plugin\Product\ProductList;
class Toolbar
{
public function aroundSetCollection(
\Magento\Catalog\Block\Product\ProductList\Toolbar $subject,
\Closure $proceed,
$collection
) {
$currentOrder = $subject->getCurrentOrder();
$result = $proceed($collection);
if ($currentOrder) {
if ($currentOrder == 'price_pcs') {
$subject->getCollection()->setOrder('(price = 0, price)', 'asc');
}
}
return $result;
}
}