How to Add Sort by Popularity in Magento 2

Enhancing your Magento 2 store with a "Sort by Popularity" feature can significantly improve user experience by allowing customers to view top-rated products first. Here's a straightforward guide to implementing this feature.

Step 1: Set Up Product Popularity

  1. Determine a metric for popularity, such as sales volume or customer reviews.
  2. Create a custom attribute if necessary, or use existing metrics like sales numbers or review ratings. This will act as the basis for sorting.

Step 2: Implement Popularity Sorting

  1. Log in to the Magento 2 admin and navigate to Catalog > Products.
  2. Under Stores > Attributes > Product, add or modify an attribute to be used for sorting by popularity. Ensure it is set as "Used for Sorting in Product Listing."

Step 3: Modify the Frontend

  1. Edit your theme’s catalog product list XML file to include a sorting option based on the popularity attribute.

 

<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar">

    <action method="setDefaultOrder">

        <argument name="order" xsi:type="string">popularity</argument>

    </action>

</block>

Extra Tools

For a more comprehensive sorting solution, consider using our Improved Sorting for Magento 2 extension, which provides enhanced sorting capabilities including popularity. With these instructions, you’ll improve the shopping experience and potentially increase conversions. 

Loading

Didn’t you find the answer to your question? We are always happy to help you out.

Loading