ขั้นตอนที่ 1 : ขั้นแรกคุณควรสร้าง register.php
ชื่อผู้ขาย: อรุณ
ชื่อโมดูล: NewSorting
  ผู้ขาย / modulename / registration.php
<?php \Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE, 'Arun_NewSorting',
__DIR__
);?>
ขั้นตอนที่ 2 : คุณสร้าง module.xml
  ผู้ขาย / modulename / etc / module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Arun_NewSorting" setup_version="0.0.1">
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>
ขั้นตอนที่ 3 : คุณสร้างปลั๊กอิน
  ผู้ขาย / modulename / 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">
    <type name="Magento\Catalog\Model\Config">
        <plugin name="Arun_NewSorting::addCustomOptions" type="Arun\NewSorting\Plugin\Model\Config" />
    </type>
    <type name="Magento\Catalog\Block\Product\ProductList\Toolbar">
        <plugin name="Arun_NewSorting::addPriceDecendingFilterInToolbar" type="Arun\NewSorting\Plugin\Product\ProductList\Toolbar" />
    </type>
</config>
ขั้นตอนที่ 4 : จากนั้นสร้าง config.php
  ผู้ขาย / modulename / ปลั๊กอิน / รุ่น / config.php
<?php
namespace Arun\NewSorting\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'];
        unset($options['position']);
        unset($options['name']);
        unset($options['price']);
        //Changing label
        $customOption['position'] = __( 'Relevance' );
        //New sorting options
        $customOption['created_at'] = __( ' New' );
        $customOption['name'] = $default_options['name'];
        //Merge default sorting options with custom options
        $options = array_merge($customOption, $options);
        return $options;
    }
}
ขั้นตอนที่ 5 : แทนที่ Toolbar.php ***
  ผู้ขาย / modulename / ปลั๊กอิน / สินค้า / ProductList / Toolbar.php
<?php
namespace Arun\NewSorting\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 == 'created_at') {
                $subject->getCollection()->setOrder('created_at', 'desc');
            } 
        }
        return $result;
    }
}
มันทำงานได้อย่างสมบูรณ์แบบ 
               
              
} elseif ( $this->getCurrentDirection() == 'asc' ) {} else {