Magento Custom Sort Option

Magento Custom Sort Option

July 23, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Custom Sort Option

Enhancing Magento Sort Options: Adding Custom Filters

Are you looking to expand the sorting capabilities of your Magento store? By default, Magento offers sorting by price, name, and popularity, but there are times when you might want to add custom options like Best Sellers, Top Rated Products, or even Exclusive Items. In this step-by-step guide, we’ll show you exactly how to achieve this.

Understanding the Default Sorting Process

Before diving into adding new sorts, let’s first understand how Magento’s default sorting works. When a customer applies a sort option on your storefront, Magento uses the Mage_Catalog_Model_Config class to determine which attributes are available for sorting and in what order they should appear.

Creating Custom Sort Options

To add custom sorts like Best Sellers or Top Rated Products, you’ll need to create corresponding attribute options. Here’s how:

  1. Create a New Attribute: Navigate to Catalog > Attributes > Manage Attributes. Click “Add New Attribute” and select the “Dropdown” type for your new attribute (e.g., “Sort Order”).

  2. Define Options: In the “Manage Label/Options” section, add options like “Best Sellers”, “Top Rated Products”, etc.

  3. Apply to Product Types: Make sure this attribute is applied to the product types you want it to affect.

Modifying the Sorting Algorithm

With the new attribute in place, we need to modify Magento’s sorting process to include our custom options. This involves overriding the core Mage_Catalog_Model_Config class.

First, create a new module in your Magento installation (e.g., MyCompany_SortExtension). Within this module, create the file app/code/local/MyCompany/SortExtension/etc/config.xml.

Add the following content to include our custom sorts:

<config>
    <global>
        <catalog>
            <resource>
                <sort_by_options>
                    <option id="best_sellers" label="Best Sellers"/>
                    <option id="top_rated" label="Top Rated Products"/>
                    <!-- Add other options here -->
                </sort_by_options>
            </resource>
        </catalog>
    </global>
</config>

Next, override the Mage_Catalog_Model_Config class in your module. Create a file at app/code/local/MyCompany/SortExtension/Model/Config.php:

class MyCompany_SortExtension_Model_Config extends Mage_Catalog_Model_Config
{
    public function getSortByOptions()
    {
        $options = parent::getSortByOptions();
        // Add your custom options here
        return $options;
    }
}

Implementing Custom Sort Logic

The final step is to implement the actual sorting logic for our new options. This typically involves writing a custom Zend_Db_Select query that sorts products based on the desired criteria (e.g., total sales for “Best Sellers” or average rating for “Top Rated Products”).

To keep this guide concise, I recommend referring to Magento’s official documentation and community forums for detailed examples of how to write these queries.

Conclusion

Adding custom sort options in Magento requires a combination of creating new attributes, modifying core configuration files, and implementing custom sorting logic. By following the steps outlined above, you can easily extend your storefront’s filtering capabilities to improve the shopping experience for your customers.

Remember that each store is unique, so always test your changes thoroughly before deploying them to a live environment. If you find yourself needing more advanced Magento development services or want to explore additional extensions and customizations, don’t hesitate to reach out to Laravel Company for expert assistance.

Happy coding!

Catalog Configuration Orders Customers

Our network