2

I'm new with Magento2, I have a problem trying to add a new filter to the search module.

For example:

I created an attribute that names: "flag" of type "text field", that will be invisible in storefront.

I have 3 products:

name | description | flag

Product1 | Description1 | 1

Product2 | Description2 | 1

Product3 | Description3 | 0

When I type in the search box "product", by default Magento2 returns all the products, because all matches with the search, what I want is add a filter to the search, that only returns the products with flag = 1, so it will returns only the product 1 and 2.

I don't know what is the exactly block or model that I must override.

3
  • Look at this answer magento.stackexchange.com/questions/90209/… Mar 2, 2016 at 20:24
  • @darkangelo, are you asking about the catalog product grid?
    – Maddy
    Mar 2, 2016 at 22:13
  • Hi Arkadii, I saw the link in your comment, but that's only work for the autocomplete search, which is good, but I need to do the same when you click on the search button
    – darkangelo
    Mar 3, 2016 at 14:36

1 Answer 1

3

Look for the grid's listing page like this. The product listing for regular catalog can be found here (it differs for configurable product etc). For your custom attribute's config, add

<item name="filter" xsi:type="string">text</item>

and the filter should show up on the header for that field.

2
  • Thanks Maddy for your answer, what I need is modify the search in frontend, the link that you gave me is for the admin
    – darkangelo
    Mar 3, 2016 at 14:40
  • Sorry I was confused about what exactly you needed.
    – Maddy
    Mar 3, 2016 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.