1

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.

  • Are you using any extension? Or used any custom coding for advanced search? – Girish SH Feb 6 '15 at 20:51
  • I just added a new block on homepage in XML layout update (catalogsearch/advanced_form). I only had to change this line <form action="<?php echo $this->getSearchPostUrl() ?>" method="get" id="form-validate"> in form.phtml TO this one <form action="<?php echo $this->getUrl('catalogsearch/advanced/result') ?>" method="get" id="form-validate"> in order to see the search result. – Williams M. Feb 6 '15 at 21:31
2

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/

2

You can rewrite this class to deal with select and multiselect frontend input types

replace this

    public function getAttributeSelectElement($attribute)
{
    $extra = '';
    $options = $attribute->getSource()->getAllOptions(false);

    $name = $attribute->getAttributeCode();

    // 2 - avoid yes/no selects to be multiselects
    if (is_array($options) && count($options)>2) {
        $extra = 'multiple="multiple" size="4"';
        $name.= '[]';
    }
    else {
        array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));
    }

with this

    public function getAttributeSelectElement($attribute)
{
    $extra = '';
    $options = $attribute->getSource()->getAllOptions(false);

    $name = $attribute->getAttributeCode();
    $front = $attribute->getFrontendInput();

    if ($front == 'multiselect') {
        $extra = 'multiple="multiple" size="4"';
        $name.= '[]';
    }
    else {
        array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));
    }
1

So the way these items are built is in the class Mage_CatalogSearch_Block_Advanced_Form. In this class you will see a function getAttributeSelectElement. This function builds the html for the select box based on the options.

The key part for us is when it checks the options.

// 2 - avoid yes/no selects to be multiselects
if (is_array($options) && count($options)>2) {
    $extra = 'multiple="multiple" size="4"';
    $name.= '[]';
}
else {
    array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));
}

Here is checks to see how many options that the attribute has and makes it multiple select if there are more than two.

First and "easiest" option would be to rewrite this class remove the extra line.

It would also be possible to listen to the before html event for select boxes of type Mage_Core_Block_Html_Select and then remove the extra parameter if set for advanced search but I think this is overly complicated and the first option would be your best bet here.

  • no problem @WilliamsM. feel free to accept the answer if this solves your problem – David Manners Mar 25 '15 at 9:46

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.