1

I want to keep the dropdown attribute along with their values at frontend (Home Page) for searching the catalog. I entered following code:

    <div class="search">
<li class="fields">
<label for="technologies"><?php echo $this->__('Technologies'); ?></label>
<div class="input-box">
    <select class=" required-entry required-entry select" >
        <?php 
             $attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','technologies');
             $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
             $attributeOptions = $attribute->getSource()->getAllOptions();
             foreach($attributeOptions as $each){?>
               <option value="<?php echo $each[value]?>"><?php echo $each["label"]?></option><?php
             }
        ?>
    </select>

    <button type="submit" title="<?php echo $this->__('Search') ?>" class="button search-button"><span><span><?php echo $this->__('Search') ?></span></span></button>

</div>
</li>
</div>

How to enable catalog search for the selected attribute value.

2

check below code

<div class="search">
<li class="fields">
<label for="technologies"><?php echo $this->__('Technologies'); ?></label>
<?php $url = Mage::getBaseUrl().'catalogsearch/advanced/result'; ?>
<form action="<?php echo $url; ?>" method="get">
<div class="input-box">
    <select class=" required-entry required-entry select" name='technologies'>           
                            <option value="">Select...</option>
                            <?php                            
                                     $attribute_code = "technologies";
                                     $attribute_details = Mage::getSingleton("eav/config")->getAttribute("catalog_product", $attribute_code); $options = $attribute_details->getSource()->getAllOptions(false); Foreach($options as $option){ 
                                        ?>
                                    <option value="<?php echo $option["value"]; ?>">
                                        <?php echo $option["label"]; ?>
                                    </option>
                            <?php
                                } 
                            ?>


    </select>
    <button type="submit" title="<?php echo $this->__('Search') ?>" class="button search-button"><span><span><?php echo $this->__('Search') ?></span></span></button>
</div>
</form>
</li>
</div>
|improve this answer|||||
  • Thank you I fllowed your code. but getting error message like "Fatal error: Undefined class constant 'getBaseUrl' " – Ramya Aug 17 '16 at 13:33
  • please use updated code and are use this code in phtml ? – Prashant Barot Aug 17 '16 at 13:35
  • is it worked or any issue ? – Prashant Barot Aug 17 '16 at 13:43
  • Thank you so much.. It worked. But how to modify it for multiple dropdowns. – Ramya Aug 18 '16 at 5:52
  • Hey I checked. It is also working for multiple dropdowns. Thank you so much – Ramya Aug 18 '16 at 6:11

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.