Question

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.

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top