zencart分类树统计商品数量
2012-07-10 11:39 来源:www.chinab4c.com 作者:ecshop专家
zencart分类树统计商品数量,这个是十分实用的功能。我们在读取zencart分类树的时候,可以直接通过分类和分类之间的关系。去取得该分类下循环的商品数量。当然了。我们必须知道分类所属于的每个级别的ID以及上下级关系。
1:includes/class/category_tree.php首先分类树数组需要先取得该数据。
$this->tree[$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'],
'parent' => $categories->fields['parent_id'],'categories_id' => $categories->fields['categories_id'],
'level' => 0,
'path' => $categories->fields['categories_id'],
'image' => $categories->fields['categories_image'],
'next_id' => false);
2:function zen_show_category($counter,$ii) 函数记录zencart分类ID
$this->box_categories_array[$ii]['categories_id'] = $this->tree[$counter]['categories_id'];
3:增加统计分类下商品数量的函数.
function zen_products_in_category_count($categories_id, $include_deactivated = false, $include_child = true, $limit = false) {
global $db;
$products_count = 0;
if ($limit) {
$limit_count = ' limit 1';
} else {
$limit_count = '';
}
if ($include_deactivated) {
$products = $db->Execute("select count(*) as total
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
where p.products_id = p2c.products_id
and p2c.categories_id = '" . (int)$categories_id . "'" . $limit_count);
} else {
$products = $db->Execute("select count(*) as total
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
where p.products_id = p2c.products_id
and p.products_status = 1
and p2c.categories_id = '" . (int)$categories_id . "'" . $limit_count);
}
$products_count += $products->fields['total'];
if ($include_child) {
$childs = $db->Execute("select categories_id from " . TABLE_CATEGORIES . "
where parent_id = '" . (int)$categories_id . "'");
if ($childs->RecordCount() > 0 ) {
while (!$childs->EOF) {
$products_count += zen_products_in_category_count($childs->fields['categories_id'], $include_deactivated);
$childs->MoveNext();
}
}
}
return $products_count;
}
4:includes/templates/template_default/sideboxes/tpl_categorires.php增加以下代码
$c = zen_products_in_category_count($box_categories_array[$i]['categories_id']);
最近更新
常用插件
- ecshop通用红包编码
很多时候,为了结合促销,必须扩展一下ecshop的红包功能。ecshop的红包...
- ecshop降价通知登记插件
ecshop降价通知登记插件,主要是为了方便某些客户,对商品价格要求比...
- ecshop购物车功能改进[插件
ecshop购物车功能改进[插件套餐]主要是我们最近开发工作和开发项目中。...
- ecshop分类树中统计商品数
最近忙于开发其他项目,在不少朋友不断要求和催促的情况下,做出了该小...
- ecshop红包修改成满多少减
我们在长期使用ecshop的时候,我们可以发现。ecshop的红包是一个非常强...