Monday , December 11 2017
Home >> All tutorial >> How to convert multi-select field to checkbox in advanced search form of Magento?

How to convert multi-select field to checkbox in advanced search form of Magento?

Today, Magento Tutorial will discuss with you how to convert multi-select field to checkbox in advanced search form of Magento.

Step 1:

Copy the following file to your working theme:
app/design/frontend/[interface]/[theme]/template/catalogsearch/advanced/form.phtml

Step 2:

Open the form.phtml (from above) and find the following line just after the case ‘select’: ?>

  1. <div class=“input-box”>
  2.     <?php echo $this->getAttributeSelectElement($_attribute) ?>
  3. </div>
and replace it by the following code:
  1. <?php if(in_array($_attribute->getAttributeCode(), array(‘manufacturer’))): ?>
  2. <div class=“input-box”>
  3.     <?php
  4.          $options = $_attribute->getSource()->getAllOptions(false);
  5.          foreach($options as $_option):
  6.              $isChecked = in_array($_option[‘value’], $this->getRequest()->getParam($_attribute->getAttributeCode())) ? ‘ checked=”checked”‘ : null;
  7.              ?>
  8.     <input type=”checkbox” name=”<?php echo $_attribute->getAttributeCode(); ?>[]” value=”<?php echo $_option[‘value’]; ?><?php echo $isChecked; ?> /> <?php echo $_option[‘label’]; ?><br />
  9.     <?php
  10.          endforeach;
  11.     ?>
  12. </div>
  13. <?php else: ?>
  14. <div class=“input-box”>
  15.     <?php echo $this->getAttributeSelectElement($_attribute); ?>
  16. </div>
  17. <?php endif; ?>

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

  1. <?php if(in_array($_attribute->getAttributeCode(), array(‘manufacturer’, ‘color’))): ?>

 Step 3:

Try to refresh the advanced search page: http://your-magento-url/catalogsearch/advanced

You will see:

Note: You can use some css in order to break the checkboxes in multi-columns for better display.

We also contribute great content of Magento Download for FREE (all versions)

DON'T MISS THE CHANCE!

magento download

About Champ

Leave a Reply

Your email address will not be published. Required fields are marked *

Heap | Mobile and Web Analytics