Magento – Quick Search Using Attributes via Parameters

catalogsearchmagento-1.9

I have this working in advanced search :

catalogsearch/advanced/result/?name=vanille&is_bio=1

Every product whose name contains "vanille" and attribute "is_bio" set to true will appear.

Now since I need to search not just in "name" but also other fields like "brands", I have to use quick search and its "q" query (correct me if I'm wrong). But in this case attributes won't have any effect :

catalogsearch/result/?q=vanille&is_bio=1

Will show every products containing "vanille" whatever the value of "is_bio".

Is there anyway to activate params in quick search ?

Best Answer

Yes you can do this. You need to go Catalog > Attributes > Manage Attributes and locate your attribute. Make sure the configuration for Use in Search Results Layered Navigation is set to Yes:

Screenshot of attribute configuration

However, note the warning underneath the option:

Can be used only with catalog input type Dropdown, Multiple Select and Price.

This means that if you are currently using a Yes/No attribute type you will need to create a new Dropdown type attribute.

Once you have your attribute set to be used in layered navigation, you can then use it as a filter in your URL, e.g. catalogsearch/result/?q=vanille&is_bio=123 (where 123 is your "Yes" attribute option ID).

There is a caveat to changing from Yes/No to the Dropdown type. If you are using this attribute elsewhere in your codebase, you will no longer be able to use the getIsBio() method to test for true/false:

if ($product->getIsBio()) {
    // won't work for Dropdown types
}

if ($product->getAttributeText('is_bio') === 'Yes') {
    // works for Dropdown types
}
Related Topic