Skip to main content
10 of 16
edited title
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144

Sort search result products by attribute option value in Magento 2

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

Scenario:

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

Which has the following options,

1.Unit.

2.Component

3.Bundle

So once We search any product I need to load the product created with "Unit" option on top for the particular search keyword which means option with Unit should load first and the rest.

Example:

3 products are created with below information.

  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 implemented? Thanks in advance!!!

Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144