magento--搜索功能添加分类选项!

magento的搜索是没有分类条件的,我们可以给他加上这个条件,在综合站搜索比较精准一些!

当然,magento的搜索设置也要设置好,太模糊的搜索会造成搜索的不精准。

下面是代码,覆盖文件template/catalogsearch/form.mini.phtml文件即可~!!!!


  1. <?php
  2. $category = Mage:: getModel ( 'catalog/category' );
  3. if ( is_object (Mage:: registry ( 'current_category' ) ) ) {
  4. $current_category_path=Mage:: registry ( 'current_category' )-> getPathIds ( );
  5. } else {
  6. $current_category_path = array ( );
  7. }
  8. $category-> load (Mage:: app ( )-> getStore ( )-> getRootCategoryId ( ) );
  9. $children_string = $category-> getChildren ( );
  10. $children = explode ( ',', $children_string );
  11. $extra_options= '';
  12. foreach ( $children as $c ) {
  13. $selected = ( in_array ( $c, $current_category_path ) )? 'SELECTED': '';
  14. $extra_options.= '<option value="' . $c . '" ' . $selected . '>' . $category-> load ( $c )-> getName ( ) . '</option>' . "\n";
  15. }
  16. ?>
  17. <form id= "search_mini_form" action= "<?php echo $this->helper('catalogSearch')->getResultUrl() ?>" method= "get">
  18. <fieldset>
  19. <legend><?php echo $this->__ ( 'Search Site' ) ?></legend>
  20. <div class= "mini-search">
  21. <input id= "search" type= "text" class= "input-text" name= "<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>" value= "<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>" />
  22. <select name= "cat" id= "cat" class= "input-text">
  23. <option value= "">All Departments</option>
  24. <?= $extra_options ?>
  25. </select>
  26. <input type= "submit" value= "Go" style= "border: 1px solid #808080;" alt= "<?php echo $this->__('Search') ?>" />
  27. <div id= "search_autocomplete" class= "search-autocomplete"></div>
  28. <script type= "text/javascript">
  29. //<![CDATA[
  30. var searchForm = new Varien.searchForm ( 'search_mini_form', 'search', '<?php echo $this->__('search site... ') ?>' );
  31. searchForm.initAutocomplete ( '<?php echo $this->helper('catalogSearch ')->getSuggestUrl() ?>', 'search_autocomplete' );
  32. //]]>
  33. </script>
  34. </div>
  35. </fieldset>
  36. </form>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值