PHP Magento Tips

Converting multi-select field to checkbox in advanced search form of Magento

Rate this posting:
{[['']]}

to converting multi-select field to checkbox in advanced search form of Magento follow below steps:

Step 1: Open the file  app/design/frontend/rwd/default/template/catalogsearch/advanced/form.phtml and search for below code:

<div class="input-box">

    <?php echo $this->getAttributeSelectElement($_attribute) ?>

</div>

and replace it by the following code:

<?php if(in_array($_attribute->getAttributeCode(), array('manufacturer', 'color'))): ?>

<div class="input-box">

    <?php

         $options = $_attribute->getSource()->getAllOptions(false);

         foreach($options as $_option):

             $isChecked = in_array($_option['value'], $this->getRequest()->getParam($_attribute->getAttributeCode())) ? ' checked="checked"' : null;

             ?>

    <input type="checkbox" name="<?php echo $_attribute->getAttributeCode(); ?>[]" value="<?php echo $_option['value']; ?>"<?php echo $isChecked; ?> /> <?php echo $_option['label']; ?><br />

    <?php

         endforeach;

    ?>

</div>

<?php else: ?>

<div class="input-box">

    <?php echo $this->getAttributeSelectElement($_attribute); ?>

</div>

<?php endif; ?>

Note: Here we have customized the display for manufacturer and color attribute, similarly you can customize for other attributes. Just you need to add the attribute code in the array.

Try to refresh the advanced search page: http://your-magento-url/catalogsearch/advanced
You will see some good results.
Tag : Magento
0 Comments On "Converting multi-select field to checkbox in advanced search form of Magento"

Back To Top