How to add custom options to Product Sort By drop down in Magento?

How to add custom options to Product Sort By drop down in Magento?

August 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to add custom options to Product Sort By drop down in Magento?

Customizing Product Sort By Options in Magento

As a new Magento developer, you’re likely to encounter a variety of customization requests from your clients. One common requirement is to modify the product sort by options available in category pages.

By default, Magento provides three sorting options: Position, Name (alphabetically), and Price (lowest first). However, your client may want to change this list or add new options like “Relevance” or “Popular.”

In this blog post, we’ll guide you through the process of customizing these sort by options in Magento. We’ll cover what files to modify and provide code examples for adding new sorting options.

Understanding the Default Sorting

Before making changes, let’s understand how Magento handles product sorting. The catalog_product table contains a column called sort_order. This is used to determine which option appears first when customers sort products on category pages.

The default options are hardcoded in the Magento core files, specifically in the Mage_Catalog_Block_Product_List::getAvailableOrders() method located at app/code/core/Mage/Catalog/Block/Product/List.php.

Adding New Sort By Options

To add new sorting options, you’ll need to create a custom module and override this core method. Here’s how:

  1. Create a new folder in your Magento root directory with the following structure: app/code/local/YourCompany/SortByOptions/

  2. Inside the SortByOptions folder, create the following files/folders:

    • etc/config.xml
    • Block/Product/List.php
    • Block/Product/List/Toolbar.php
  3. In config.xml, add the following configuration to enable your module:

<config>
    <modules>
        <YourCompany_SortByOptions>
            <version>0.1.0</version>
        </YourCompany_SortByOptions>
    </modules>

    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <product_list>YourCompany_SortByOptions_Block_Product_List</product_list>
                    <product_list_toolbar>YourCompany_SortByOptions_Block_Product_List_Toolbar</product_list_toolbar>
                </rewrite>
            </catalog>
        </blocks>
    </global>
</config>
  1. Now, let’s override the getAvailableOrders() method in app/code/local/YourCompany/SortByOptions/Block/Product/List.php. Open this file and add your custom sorting options:
public function getAvailableOrders()
{
    $coll = Mage::getSingleton('catalog/config')->getAttributeUsedForSortByArray();
    $options = array();

    foreach ($coll as $code) {
        if (isset($this->_availableAttributeCodes[$code])) {
            continue;
        }
        $attribute  = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $code);
        if (!$this->isSortable($attribute)) {
            continue;
        }

        $options[$code] = $attribute->getStoreLabel();
    }

    // Add your custom options here
    $options['relevance']  = 'Relevance';
    $options['popular']   = 'Popular';

    return $options;
}
  1. Save the file and clear your Magento cache.

Testing Your Changes

To verify that your new sort by options are visible, navigate to a category page on your Magento site. You should now see “Relevance” and “Popular” as additional sorting choices in the drop-down menu.

Remember, this is a basic example of overriding a core file. In a production environment, you should always use proper version control systems like Git and follow best practices for extending Magento functionality as recommended by our experts at Laravel Company.

Conclusion

Customizing the product sort by options in Magento requires creating a custom module to override core functionality. By following the steps outlined above, you can easily add new sorting choices like “Relevance” or “Popular.”

Always ensure your modifications are properly version controlled and tested before deploying them to live sites. If you’re looking for professional help with complex Magento projects, don’t hesitate to contact our team at Laravel Company. We provide expert development services to help businesses succeed online.

Happy coding!

Catalog Database Extensions Orders

Our network