Magento – How to change the order of the form fields of the catalog advanced search form

advanced-searchmagento-1.9

I have added a couple of custom attributes to the catalog advanced search form, but they appear in the order you add them. With the last attribute added at the bottom of the form. I would like to change the order of form fields to make it a bit more intuitive for my visitors. How can I do this?

Best Answer

The advanced form in the base template is in the file app/design/frontend/base/default/template/catalogsearch/advanced/form.phtml and it loads the attributes to show as part for a foreach loop.

It uses the function call Mage_CatalogSearch_Block_Advanced_Form::getSearchableAttributes to load the attributes. Which intern loads a collection of attributes with the filter use in advanced search but sadly only uses attribute id as the order.

->setOrder('main_table.attribute_id', 'asc')

I see you have two options:

  1. Extend Mage_CatalogSearch_Model_Advanced::getAttributes and set your own order in the collection. You could extend the attribute table to have a new column to order attribute by.
  2. Extend Mage_CatalogSearch_Block_Advanced_Form::getSearchableAttributes and perform some form of processing on the attributes so that they appear in the order that you desire.

For me option 1 would be the cleanest and you could extend the system so that the admin user could specify the order they want, but it would also be the most work.

Related Topic