How to Add Filterable Product Attribute in “Products in Category” in Magento 2

add filterable product attribute in Product in Category in Magento 2

Product attributes define characteristics of the products. One can uniquely describe the product by adding the product attributes and they heavily influence customers’ buying decisions. Apart from the default product attributes, you can easily create a product attribute in Magento 2 while creating a product, or from the product attribute page.

For instance, you create a product attribute named “Giftable Products” with the values like Yes and No. Now while checking all the products of a category from “Products in Category” under the category edit, you require to filter the products by the giftable products attribute. To achieve the result, you require to add filterable product attribute in “Product in Category” under the category edit option.

Using the default Magento 2, one cannot get filterable products result for the category products and thus, I’m here with the solution to add filterable product attribute in “Products in Category” in Magento 2.

Programmatic Solution to Add Filterable Product Attribute in “Products in Category” in Magento 2

  1. First of all, create a Product Attribute named Giftable Products. For that,
    1. Login to the admin panel.
    2. Navigate to Stores > Attributes > Product 
    3. Click Add New Attribute
      add filterable product attribute in "Product in Category" in Magento 2
    4. Create an attribute as per the above image. We have set dropdown as an input type.
    5. Click Save Attributes
  2. Create di.xml at Vendor/Module/etc/adminhtml/
  3. Create Product.php under Vendor/Module/Block/Adminhtml/Category/Tab/

After following the above steps, you can filter the products in category by the added filterable product attribute as below:

Add Filterable Product Attribute in "Product in Category" in Magento 2

That’s it.

If you need queries regarding this blog, feel free to ask in the Comment section below.

I’d be happy to answer.

Do consider sharing this post with Magento Community via social media.

Thank you.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 8 Reviews)

Krishna is a Magento developer at Meetanshi. She is always ready to learn new things. Apart from work, she likes to read books and spend time with family.

Leave a reply:

Your email address will not be published.