How to Add Sort by Position in Magento 2

Adding a "Sort by Position" functionality to your Magento 2 store can enhance the shopping experience by allowing customers to view products in a preferred order. Here's a simple guide to implementing this feature.

Step 1: Modify the Product List

  1. Navigate to your Magento 2 admin panel and go to the Catalog section.
  2. Under Attributes, select Product. Find the position attribute and ensure it is set as "Used for Sorting in Product Listing."

Step 2: Update the Storefront

  1. Go to Stores > Configuration.
  2. In the left panel, select Catalog then Catalog Search. Ensure that the Use Flat Catalog Product and Use Flat Catalog Category are enabled. This can optimize performance and ensure your settings take effect.

Step 3: Adjust the Template

  1. To modify how products are displayed, locate your theme’s catalog product list XML file and add an option for sorting by position.

 

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

    <action method="setDefaultOrder">

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

    </action>

</block>

Additional Resources

If you're looking for a more advanced sorting solution, consider using our Improved Sorting for Magento 2 extension, which provides additional sorting options and enhanced functionality.

By incorporating these steps, you’ll improve your store’s usability and potentially boost conversion rates, creating a seamless experience for your customers. 

Loading

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

Loading