对于magento默认的搜索,是不带有分类选项的,当你的网店是一个综合站,每一个分类下面放的是不同类型的产品,那么为了更加精确地搜索,需要增加一个分类选项,毕竟,你不喜欢在搜索球衣的时候出来避孕套吧?呵呵
既然这样,加上后客户体验还能增加,就让我们加上magento分类选项吧!!
-
<?php
-
$category = Mage::getModel('catalog/category');
-
$current_category_path=Mage::registry('current_category')->getPathIds();
-
}else{
-
}
-
$category->load(Mage::app()->getStore()->getRootCategoryId());
-
$children_string = $category->getChildren();
-
$extra_options='';
-
foreach($children as $c){
-
$extra_options.= '<option value="' . $c . '" ' . $selected . '>' . $category->load($c)->getName() . '</option>' . "\n";
-
}
-
?>
-
<form id="search_mini_form" action="<?php echo $this->helper('catalogSearch')->getResultUrl() ?>" method="get">
-
<fieldset>
-
<div class="mini-search">
-
<input id="search" type="text" class="input-text" name="<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>" value="<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>" />
-
<select name="cat" id="cat" class="input-text">
-
<option value="">All Departments</option>
-
<?= $extra_options ?>
-
</select>
-
<input type="submit" value="Go" style="border: 1px solid #808080;" alt="<?php echo $this->__('Search') ?>" />
-
<div id="search_autocomplete" class="search-autocomplete"></div>
-
<script type="text/javascript">
-
//<![CDATA[
-
var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('search site...') ?>');
-
searchForm.initAutocomplete('<?php echo $this->helper('catalogSearch')->getSuggestUrl() ?>', 'search_autocomplete');
-
//]]>
-
</script>
-
</div>
-
</fieldset>
-
</form>
在magento相应的模板中覆盖template/catalogsearch/form.mini.phtml文件即可~!!!!,然后刷新缓存,编译,你会发现搜索的旁边出来一个分类选项!