$category= Mage::getModel('catalog/category');
if(is_object(Mage::registry('current_category'))){
$current_category_path=Mage::registry('current_category')->getPathIds();
}else{
$current_category_path= array();
}
$category->load(Mage::app()->getStore()->getRootCategoryId());
$children_string= $category->getChildren();
$children= explode(',',$children_string);
$extra_options='';
foreach($childrenas$c){
$selected= (in_array($c, $current_category_path))?'SELECTED':'';
$extra_options.= '<option class="parent-cat" value="'. $c. '" '. $selected. '>'. $category->load($c)->getName() . '</option>'. "\n";
}
?>
<form id="search_mini_form"action="<?php echo $this->helper('catalogSearch')->getResultUrl() ?>"method="get">
<fieldset>
<table height="33"cellspacing="0"cellpadding="0"border="0"width="472">
<tbody>
<tr>
<td id="nav-search-field"align="left"width="260"> <input id="search"type="text"class="input-live-search"name="<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>"value="<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>"/></td>
<td class="category_search_select"width="90">
<select name="cat"id="cat">
<option value=""><?php echo$this->__('All Categories') ?></option>
<?php echo$extra_options; ?>
</select>
</td>
<td align="center"width="45"style="text-align:center">
<input type="image"style="margin-top:1px;"src="<?php echo $this->getSkinUrl('images/nav_searchbar_submit.gif') ?>"alt="search"/>
</td>
<td align="center"width:="77">
<a href="<?php echo $this->getUrl('catalogsearch/advanced') ?>"><?php echo$this->__('Advanced') ?></a>
</td>
<div id="search_autocomplete"class="search-autocomplete"></div>
<script type="text/javascript">
//<![CDATA[
varsearchForm = newVarien.searchForm('search_mini_form', 'search', '<?php echo $this->__('search site...') ?>');
searchForm.initAutocomplete('<?php echo $this->helper('catalogSearch')->getSuggestUrl() ?>', 'search_autocomplete');
//]]>
</script>
</div>
</tr>
</tbody>
</table>
</fieldset>
</form>
给Magento搜索添加分类下拉菜单
2013年1月14日星期一 Asia/Shanghai下午3:43:28
Posted By