最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > 建站教程 > CMS教程 > ECShop教程 >

Ecshop实现商品分类树显示分类下商品数量

时间:2014-12-20 15:47来源:未知 作者:最模板zuimoban 点击: 次
我们会看到很多的网站可以看到有分类并且可以显示当前分类有多少商品数量了,下面我来给大家介绍实现方法. 非常简单的改动 1、includes/lib_goods.php下,找到这两个函数改成我这样就行

我们会看到很多的网站可以看到有分类并且可以显示当前分类有多少商品数量了,下面我来给大家介绍实现方法.

非常简单的改动

1、includes/lib_goods.php下,找到这两个函数改成我这样就行,代码如下:

  1. function get_categories_tree($cat_id = 0) 
  2. function get_child_tree($tree_id = 0) 
  3.  
  4. /** 
  5.  * 获得指定分类同级的所有分类以及该分类下的子分类 
  6.  * 
  7.  * @access  public 
  8.  * @param   integer     $cat_id     分类编号 
  9.  * @return  array 
  10.  */ 
  11. function get_categories_tree($cat_id = 0) 
  12. { 
  13.     if ($cat_id > 0) 
  14.     { 
  15.         $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'"; 
  16.         $parent_id = $GLOBALS['db']->getOne($sql); 
  17.     } 
  18.     else 
  19.     { 
  20.         $parent_id = 0; 
  21.     } 
  22.  
  23.     /* 
  24.      判断当前分类中全是是否是底级分类, 
  25.      如果是取出底级分类上级分类, 
  26.      如果不是取当前分类及其下的子分类 
  27.     */ 
  28.     $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 "; 
  29.     if ($GLOBALS['db']->getOne($sql) || $parent_id == 0) 
  30.     { 
  31.         /* 获取当前分类及其子分类 */ 
  32.         $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' . 
  33.                 'FROM ' . $GLOBALS['ecs']->table('category') . 
  34.                 "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC"; 
  35.  
  36.         $res = $GLOBALS['db']->getAll($sql); 
  37.  
  38.         foreach ($res AS $row) 
  39.         { 
  40.             if ($row['is_show']) 
  41.             { 
  42.                 /*获得分类下商品总数 雕鹰团队:QQ284265134 */ 
  43.                 $children = get_children($row['cat_id']); 
  44.                 $sql = 'SELECT count(*)' . "FROM " . $GLOBALS['ecs']->table('goods') . ' AS g '. 
  45.                 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND '. 
  46.                  'g.is_delete = 0 AND (' . $children . 'OR ' . get_extension_goods($children) . ') '; 
  47.                 $cat_goods_num=$GLOBALS['db']->getOne($sql); 
  48.                 $cat_arr[$row['cat_id']]['goods_num']   = $cat_goods_num == '' ? 0 : $cat_goods_num; 
  49.                 
  50.                 $cat_arr[$row['cat_id']]['id']   = $row['cat_id']; 
  51.                 $cat_arr[$row['cat_id']]['name'] = $row['cat_name']; 
  52.                 $cat_arr[$row['cat_id']]['url']  = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); 
  53.  
  54.                 if (isset($row['cat_id']) != NULL) 
  55.                 { 
  56.                     $cat_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']); 
  57.                 } 
  58.             } 
  59.         } 
  60.     } 
  61.     if(isset($cat_arr)) 
  62.     { 
  63.         return $cat_arr; 
  64.     } 
  65. } 
  66.  
  67. function get_child_tree($tree_id = 0) 
  68. { 
  69.     $three_arr = array(); 
  70.     $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 "; 
  71.     if ($GLOBALS['db']->getOne($sql) || $tree_id == 0) 
  72.     { 
  73.         $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' . 
  74.                 'FROM ' . $GLOBALS['ecs']->table('category') . 
  75.                 "WHERE parent_id = '$tree_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC"; 
  76.         $res = $GLOBALS['db']->getAll($child_sql); 
  77.         foreach ($res AS $row) 
  78.         { 
  79.                 /*获得分类下商品总数 雕鹰团队:QQ284265134 */ 
  80.                 $children = get_children($row['cat_id']); 
  81.                 $sql = 'SELECT count(*)' . "FROM " . $GLOBALS['ecs']->table('goods') . ' AS g '. 
  82.                 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND '. 
  83.                  'g.is_delete = 0 AND (' . $children . 'OR ' . get_extension_goods($children) . ') '; 
  84.                 $cat_goods_num=$GLOBALS['db']->getOne($sql); 
  85.                 $three_arr[$row['cat_id']]['goods_num']   = $cat_goods_num == '' ? 0 : $cat_goods_num; 
  86.                 
  87.             if ($row['is_show']) 
  88.  
  89.                $three_arr[$row['cat_id']]['id']   = $row['cat_id']; 
  90.                $three_arr[$row['cat_id']]['name'] = $row['cat_name']; 
  91.                $three_arr[$row['cat_id']]['url']  = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); 
  92.  
  93.                if (isset($row['cat_id']) != NULL) 
  94.                    { 
  95.                        $three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);  //开源软件:vcphp.com 
  96.  
  97.             } 
  98.         } 
  99.     } 
  100.     return $three_arr; 
  101. } 

library/group_buy.lbi

注意这里:原版的lefttime.js是定义的单个ID

<font id="leftTime" class="f1"> 这里循环了,ID重复一定报错,这里怎么解决呢?你可以自己从JS文件夹里新复制一个lefttime.js这里我命名为:lefttime1.js;调用如下代码:

  1. <script type="text/javascript" src="js/lefttime1.js"></script> 
  2.  
  3.  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gbk"> 
  5. <script type="text/javascript" src="js/lefttime.js"></script> 
  6.  
  7.  
  8. <!-- {if $group_buy_goods} --> 
  9. <div class="box" style="border:1px solid #e2e2e2; width:198px;"> 
  10. <h3><span>{$lang.group_buy_goods}</span></h3> 
  11. <div class="box_1" style="border:none;"> 
  12. <div class="boxCenterList clearfix"> 
  13.       <!--{foreach from=$group_buy_goods item=goods}--> 
  14.       <ul class="clearfix" style="position:relative;"> 
  15.            <li class="goodsimg" style="width:190px; height:190px; margin:0px;"><a style=" margin:0px;width:190px; height:190px;" href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.goods_name|escape:html}" class="goodsimg" style=" margin:0;width:190px; height:190px;" /></a></li> 
  16.                 <li style="text-align:center; width:200px; overflow:hidden; font-size:14px; font-weight:bold;"><a href="{$goods.url}" title="{$goods.goods_name|escape:html}">{$goods.short_style_name|escape:html}</a></li> 
  17.                 <li style="width:100%;"><font class="shop_s">{$goods.last_price}</font></li> 
  18.                 <div class="index_group">售出 <strong>{$goods.vn}</strong> 件</div> 
  19.                 剩余时间:<span id="leftTime">结束时间:{$goods.gmt_end_date}</span> 
  20.         </ul> 
  21.       <!--{/foreach}--> 
  22.     </div> 
  23.      
  24. </div> 
  25. </div> 
  26. <div class="blank"></div> 
  27. <!-- {/if} --> 
  28.  
  29. <script type="text/javascript"> 
  30. var gmt_end_time = "{$goods.gmt_end_date|default:0}"; 
  31. {foreach from=$lang.goods_js item=item key=key} 
  32. var {$key} = "{$item}"; 
  33. {/foreach} 
  34. var now_time = "{$goods.gmt_now_date|default:0}"; 
  35. <!-- {literal} --> 
  36. //开源软件:vcphp.com 
  37. onload = function() 
  38. { 
  39.   try 
  40.   { 
  41.     onload_leftTime(); 
  42.   } 
  43.   catch (e) 
  44.   {} 
  45. } 
  46. <!-- {/literal} --> 
  47. </script>
(责任编辑:最模板)
------分隔线----------------------------
栏目列表
推荐内容