Ecshop实现商品分类树显示分类下商品数量
发布:smiling 来源: PHP粉丝网 添加日期:2014-12-06 16:49:48 浏览: 评论:0
我们会看到很多的网站可以看到有分类并且可以显示当前分类有多少商品数量了,下面我来给大家介绍实现方法.
非常简单的改动
1、includes/lib_goods.php下,找到这两个函数改成我这样就行,代码如下:
- function get_categories_tree($cat_id = 0)
- function get_child_tree($tree_id = 0)
- /**
- * 获得指定分类同级的所有分类以及该分类下的子分类
- *
- * @access public
- * @param integer $cat_id 分类编号
- * @return array
- */
- function get_categories_tree($cat_id = 0)
- {
- if ($cat_id > 0)
- {
- $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'";
- $parent_id = $GLOBALS['db']->getOne($sql);
- }
- else
- {
- $parent_id = 0;
- }
- /*
- 判断当前分类中全是是否是底级分类,
- 如果是取出底级分类上级分类,
- 如果不是取当前分类及其下的子分类
- */
- $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
- if ($GLOBALS['db']->getOne($sql) || $parent_id == 0)
- {
- /* 获取当前分类及其子分类 */
- $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' .
- 'FROM ' . $GLOBALS['ecs']->table('category') .
- "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
- $res = $GLOBALS['db']->getAll($sql);
- foreach ($res AS $row)
- {
- if ($row['is_show'])
- {
- /*获得分类下商品总数 雕鹰团队:QQ284265134 */
- $children = get_children($row['cat_id']);
- $sql = 'SELECT count(*)' . "FROM " . $GLOBALS['ecs']->table('goods') . ' AS g '.
- 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND '.
- 'g.is_delete = 0 AND (' . $children . 'OR ' . get_extension_goods($children) . ') ';
- $cat_goods_num=$GLOBALS['db']->getOne($sql);
- $cat_arr[$row['cat_id']]['goods_num'] = $cat_goods_num == '' ? 0 : $cat_goods_num;
- $cat_arr[$row['cat_id']]['id'] = $row['cat_id'];
- $cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
- $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
- if (isset($row['cat_id']) != NULL)
- {
- $cat_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
- }
- }
- }
- }
- if(isset($cat_arr))
- {
- return $cat_arr;
- }
- }
- function get_child_tree($tree_id = 0)
- {
- $three_arr = array();
- $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 ";
- if ($GLOBALS['db']->getOne($sql) || $tree_id == 0)
- {
- $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
- 'FROM ' . $GLOBALS['ecs']->table('category') .
- "WHERE parent_id = '$tree_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
- $res = $GLOBALS['db']->getAll($child_sql);
- foreach ($res AS $row)
- {
- /*获得分类下商品总数 雕鹰团队:QQ284265134 */
- $children = get_children($row['cat_id']);
- $sql = 'SELECT count(*)' . "FROM " . $GLOBALS['ecs']->table('goods') . ' AS g '.
- 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND '.
- 'g.is_delete = 0 AND (' . $children . 'OR ' . get_extension_goods($children) . ') ';
- $cat_goods_num=$GLOBALS['db']->getOne($sql);
- $three_arr[$row['cat_id']]['goods_num'] = $cat_goods_num == '' ? 0 : $cat_goods_num;
- if ($row['is_show'])
- $three_arr[$row['cat_id']]['id'] = $row['cat_id'];
- $three_arr[$row['cat_id']]['name'] = $row['cat_name'];
- $three_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
- if (isset($row['cat_id']) != NULL)
- {
- $three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']); //开源软件:phpfensi.com
- }
- }
- }
- return $three_arr;
- }
library/group_buy.lbi
注意这里:原版的lefttime.js是定义的单个ID
<font id="leftTime" class="f1"> 这里循环了,ID重复一定报错,这里怎么解决呢?你可以自己从JS文件夹里新复制一个lefttime.js这里我命名为:lefttime1.js;调用如下代码:
- <script type="text/javascript" src="js/lefttime1.js"></script>
- <meta http-equiv="Content-Type" content="text/html; charset=gbk">
- <script type="text/javascript" src="js/lefttime.js"></script>
- <!-- {if $group_buy_goods} -->
- <div class="box" style="border:1px solid #e2e2e2; width:198px;">
- <h3><span>{$lang.group_buy_goods}</span></h3>
- <div class="box_1" style="border:none;">
- <div class="boxCenterList clearfix">
- <!--{foreach from=$group_buy_goods item=goods}-->
- <ul class="clearfix" style="position:relative;">
- <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>
- <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>
- <li style="width:100%;"><font class="shop_s">{$goods.last_price}</font></li>
- <div class="index_group">售出 <strong>{$goods.vn}</strong> 件</div>
- 剩余时间:<span id="leftTime">结束时间:{$goods.gmt_end_date}</span>
- </ul>
- <!--{/foreach}-->
- </div>
- </div>
- </div>
- <div class="blank"></div>
- <!-- {/if} -->
- <script type="text/javascript">
- var gmt_end_time = "{$goods.gmt_end_date|default:0}";
- {foreach from=$lang.goods_js item=item key=key}
- var {$key} = "{$item}";
- {/foreach}
- var now_time = "{$goods.gmt_now_date|default:0}";
- <!-- {literal} -->
- //开源软件:phpfensi.com
- onload = function()
- {
- try
- {
- onload_leftTime();
- }
- catch (e)
- {}
- }
- <!-- {/literal} -->
- </script>
Tags: Ecshop商品数量 Ecshop分类树
- 上一篇:ecshop购物车退出不清空几种方法
- 下一篇:ecshop验证码不显示解决办法
相关文章
- ·让ECshop分类页的商品分类树与首页的商品分类树一样(2015-09-28)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)