Skip to main content
2 of 16
added 11 characters in body
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144

Sort search result products by attribute value in Magento 2

I want to sort the search result collection by product attribute value.

Scenario:

I have created a custom attribute called "product_category" as a drop down attribute.

Which has the below options,

1.Unit.

2.Component

3.Bundle

So once we search any product i need to load the product created with "Unit" option first for the particular keyword match.

Example:

3 products are created with below data.

  1. Unit Test product - product_category attribute value is set as "Unit".

  2. Test bundle product - product_category attribute value is set as "Bundle".

  3. Test component product - product_category attribute value is set as "Component".

So whenever i searched the keyword, "Test Product" I need to load the product where product_category attribute value is set as "Unit" on top in search result page.

Can anyone help me how this can be achieved? Thanks in advance!!

Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144