Changing the new product widget sort order in Magento

Changing the new product widget sort order in Magento

September 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Changing the new product widget sort order in Magento

Changing the New Product Widget Sort Order in Magento

If you’re using Magento for your e-commerce platform, you likely want to showcase new products on your homepage to attract customers’ attention. By default, Magento sorts these products by creation date, but as a store owner, you might prefer to display them based on other criteria like popularity or relevance to current promotions.

Understanding the Default Sorting Behavior

Before we dive into changing the sorting order, let’s understand how Magento arranges its new products widget:

  • By default, it displays items ordered by creation date in descending order.
  • This means the newest products appear at the top of the list regardless of their popularity or relevance to customers.

Changing the Sort Order: A Step-by-Step Guide

To modify this behavior without touching core files, we’ll use Magento’s built-in sorting options combined with a plugin. Here’s how:

1. Define Your Sorting Criteria

Consider what makes sense for your business:

  • Popularity (based on views or orders)
  • Relevance to current promotions
  • Manual curation

Let’s assume you want to sort by the number of times each product has been viewed.

2. Create a Plugin

In your custom module, create a plugin for the Magento\NewProductsWidget\Model\NewProductList class:

public function afterGetItems(\Magento\NewProductsWidget\Model\NewProductList $subject, $result)
{
    usort($result->getItems(), function ($a, $b) {
        return $b->getViewedCount() - $a->getViewedCount();
    });

    return $result;
}

This plugin sorts the product items by their viewed count in descending order.

3. Register Your Plugin

Update your module’s etc/di.xml file to register this new plugin:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\NewProductsWidget\Model\NewProductList">
        <plugin name="sort_products_by_viewed_count" type="Vendor\ModuleName\Model\Plugin\SortByViewedCount" sortOrder="10"/>
    </type>
</config>

Replace Vendor and ModuleName with your actual vendor code.

4. Flush Cache

After making these changes, don’t forget to flush Magento’s cache from the Admin panel under System > Tools > Cache Management.

Best Practices for Managing Sort Orders

Remember these tips when working with sorting in Magento:

  • Always use plugins rather than direct core file modifications.
  • Be specific about your sorting criteria; vague rules can lead to confusion.
  • Test thoroughly after making changes, especially around promotional periods.

Conclusion: Seize Control of Your Product Display

By following this guide, you’ve learned how to take command of the new products widget’s sort order in Magento. This empowers you to create more engaging and relevant shopping experiences for your customers while keeping your site performance optimized.

Laravel Company specializes in helping businesses like yours unlock the full potential of Magento – from custom theme development [link to our themes page] to complex extension creation [link to our extensions]. Contact us today to discuss how we can help you achieve your e-commerce goals with professional, secure, and high-performing solutions.

Catalog Extensions Themes Orders

Our network