In my magento "advanced search" I have some attributes to be chosen via a dropwdown box. When the user loads the page all the fields default to "all".

array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));

What I need to do is to give a default value to just one of the fields, for example I want "color" to default to "red", so that the user has to change it manually if he wants to search for "green" or "yellow" or "all".

I tried defining the needed attributes as "default" in the config section but this only seems to work in defining an attribute in the admin interface, not in the search.

1 Answer 1


This is interesting as you can set a default value via the admin section but this appears to be ignored on the advanced search form. The key information is as follows.

From the function getAttributeSelectElement

In the class Mage_CatalogSearch_Block_Advanced_Form

Line 220 ->setValue($this->getAttributeValue($attribute))

This loads the value from the query and populates the form. What I would suggest is to rewrite the Mage_CatalogSearch_Block_Advanced_Form class and check to see if there has actually been a query submitted.

You can load the query with $this->getRequest()->getQuery(); then check to see if this is empty. If it is empty then use $attribute->getDefaultValue() to load the default value set via the admin section.

  • What do you mean with "check to see if there has actually been a query submitted" ?
    – TopperH
    Commented Mar 15, 2013 at 12:08
  • I have edited my answer with information about the query. Commented Mar 15, 2013 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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