Magento – How to show drop down list in advanced search

advanced-searchcatalogsearchdropdown-attributemagento-1.9

I added the advanced search on my homepage and this is my question:
Is there any way to show drop down lists instead of multiselect boxes?

Thank you very much.

Best Answer

File Location : Beeon\CatalogSearch\Block\Advance\Form.php

class Beeon_CatalogSearch_Block_Advance_Form extends Mage_CatalogSearch_Block_Advanced_Form
{
    public function getAttributeSelectElement($attribute)
    {
        $extra = '';
        $options = $attribute->getSource()->getAllOptions(false);
 array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));

        $name = $attribute->getAttributeCode();

        // 2 - avoid yes/no selects to be multiselects
        if (is_array($options)) {
            $extra = '';
            $name.= '[]';
        }
        else {
            array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));
        }
             return $this->_getSelectBlock()
            ->setName($name)
            ->setId($attribute->getAttributeCode())
            ->setTitle($this->getAttributeLabel($attribute))
            ->setExtraParams($extra)
            ->setValue($this->getAttributeValue($attribute))
            ->setOptions($options)
            ->setClass('')
            ->getHtml();
    }
}

Activate a magento module
File Location : Beeon\CatalogSearch\etc\config.xml

config>
    global>
        blocks>
            catalogsearch>
                rewrite>
                    advanced_form>Beeon_CatalogSearch_Block_Advance_Form
                /rewrite>
            /catalogsearch>
        /blocks>
    /global>
/config>

More details : http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/

Related Topic