Skip to content

Below code for PLP page Sort-By Price Low-High & High-Low working properly in M2.3.6 EE but not in M2.4.5 EE , any solution?

Lokesh/CatalogExtended/etc/di.xml

    <?xml version="1.0" ?>
    <type name="MagentoCatalogBlockProductProductListToolbar">
        <plugin disabled="false" name="Lokesh_CatalogExtended_Block_Toolbar" sortOrder="10" type="LokeshCatalogExtendedPluginCatalogBlockToolbar"/>
    </type>
    <type name="MagentoCatalogModelConfig">
        <plugin disabled="false" name="Lokesh_CatalogExtended_Model_Config" sortOrder="11" type="LokeshCatalogExtendedPluginCatalogModelConfig"/>
    </type>
</config>

Lokesh/CatalogExtended/Plugin/Catalog/Block/Toolbar.php

    namespace LokeshCatalogExtendedPluginCatalogBlock;

class Toolbar
{
    public function aroundSetCollection(
    MagentoCatalogBlockProductProductListToolbar $subject,
    Closure $proceed,
    $collection
    ) {
    $currentOrder = $subject->getCurrentOrder();
    $result = $proceed($collection);

    if ($currentOrder) {
        if ($currentOrder == 'high_to_low') {
            $subject->getCollection()->setOrder('price', 'desc');
        } elseif ($currentOrder == 'low_to_high') {
            $subject->getCollection()->setOrder('price', 'asc');
        }
    }

    return $result;
    }}

Lokesh/CatalogExtended/Plugin/Catalog/Model/Config.php

    namespace LokeshCatalogExtendedPluginCatalogModel;
class Config
{
      public function afterGetAttributeUsedForSortByArray(
      MagentoCatalogModelConfig $catalogConfig,
      $options
      ) {

          $options['low_to_high'] = __('Price - Low To High');
          $options['high_to_low'] = __('Price - High To Low');
          $options['position'] = __('Best Sellers');
          $options['name'] = __('Name');

          unset($options['price']);
          return $options;
      }}