ECSHOP 商品分类树显示商品总数的方法
时间:2024年01月31日
/来源:网络
/编辑:佚名
效果如图:
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'])
{
/*获得分类下商品总数 begin-老杨:QQ359199843 */
$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)
{
/*获得分类下商品总数 begin-老杨:QQ359199843 */
$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']);
}
}
}
return $three_arr;
}
复制代码
在模板文件中,可能是category_tree.lbi中,也可能是别的库文件名,总之看模板去改
在{$cat.name}后添加:({$cat.goods_num})
在{$child.name}后添加:({$child.goods_num})
在{$childer.name}后添加:({$childer.goods_num})
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'])
{
/*获得分类下商品总数 begin-老杨:QQ359199843 */
$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)
{
/*获得分类下商品总数 begin-老杨:QQ359199843 */
$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']);
}
}
}
return $three_arr;
}
复制代码
在模板文件中,可能是category_tree.lbi中,也可能是别的库文件名,总之看模板去改
在{$cat.name}后添加:({$cat.goods_num})
在{$child.name}后添加:({$child.goods_num})
在{$childer.name}后添加:({$childer.goods_num})
新闻资讯 更多
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法