类似京东的全部商品分类, 急求, 试了很多方法都不能成功调用...
回复内容: 请教各位大神, ecshop商品属性多条件筛选, 只能在商品分类列表页才能实现, 请问如何才能在全站都能实现这个功能呢?
类似京东的全部商品分类, 急求, 试了很多方法都不能成功调用...
该问题已经解决, 贴出来给大家分享一下, 如果不正确的地方, 希望指出, 谢谢
把下面这段代码 copy到程序根目录 index.php里面
/** * 获得分类的信息 * * @param integer $cat_id * * @return void */ function get_cat_info($cat_id) { return $globals['db']->getrow('select cat_name, keywords, cat_desc, style, grade, filter_attr, parent_id from ' . $globals['ecs']->table('category') . where cat_id = '$cat_id'); } /** * 获取商品类型属性 * @param $cat_id 栏目id * @return array 商品属性 */ function get_my_class($cat_id) { $children = get_children($cat_id); $cat = get_cat_info($cat_id); // 获得分类的相关信息 /* 属性筛选 */ $ext = ''; //商品查询条件扩展 if ($cat['filter_attr'] > 0) { $cat_filter_attr = explode(',', $cat['filter_attr']); //提取出此分类的筛选属性 $all_attr_list = array(); foreach ($cat_filter_attr as $key => $value) { $sql = select a.attr_name from . $globals['ecs']->table('attribute') . as a, . $globals['ecs']->table('goods_attr') . as ga, . $globals['ecs']->table('goods') . as g where ($children or . get_extension_goods($children) . ) and a.attr_id = ga.attr_id and g.goods_id = ga.goods_id and g.is_delete = 0 and g.is_on_sale = 1 and g.is_alone_sale = 1 and a.attr_id='$value'; if($temp_name = $globals['db']->getone($sql)) { $all_attr_list[$key]['filter_attr_name'] = $temp_name; $sql = select a.attr_id, min(a.goods_attr_id ) as goods_id, a.attr_value as attr_value from . $globals['ecs']->table('goods_attr') . as a, . $globals['ecs']->table('goods') . as g . where ($children or . get_extension_goods($children) . ') and g.goods_id = a.goods_id and g.is_delete = 0 and g.is_on_sale = 1 and g.is_alone_sale = 1 '. and a.attr_id='$value' . group by a.attr_value; $attr_list = $globals['db']->getall($sql); $temp_arrt_url_arr = array(); for ($i = 0; $i $cat_id, 'bid'=>$brand, 'price_min'=>$price_min, 'price_max'=>$price_max, 'filter_attr'=>$temp_arrt_url), $cat['cat_name']); $all_attr_list[$key]['attr_list'][0]['selected'] = empty($filter_attr[$key]) ? 1 : 0; foreach ($attr_list as $k => $v) { $temp_key = $k + 1; $temp_arrt_url_arr[$key] = $v['goods_id']; //为url中代表当前筛选属性的位置变量赋值,并生成以‘.’分隔的筛选属性字符串 $temp_arrt_url = implode('.', $temp_arrt_url_arr); $all_attr_list[$key]['attr_list'][$temp_key]['attr_value'] = $v['attr_value']; $all_attr_list[$key]['attr_list'][$temp_key]['url'] = build_uri('category', array('cid'=>$cat_id, 'bid'=>$brand, 'price_min'=>$price_min, 'price_max'=>$price_max, 'filter_attr'=>$temp_arrt_url), $cat['cat_name']); if (!empty($filter_attr[$key]) and $filter_attr[$key] == $v['goods_id']) { $all_attr_list[$key]['attr_list'][$temp_key]['selected'] = 1; } else { $all_attr_list[$key]['attr_list'][$temp_key]['selected'] = 0; } } } } /* 扩展商品查询条件 */ if (!empty($filter_attr)) { $ext_sql = select distinct(b.goods_id) from . $globals['ecs']->table('goods_attr') . as a, . $globals['ecs']->table('goods_attr') . as b . where ; $ext_group_goods = array(); foreach ($filter_attr as $k => $v) // 查出符合所有筛选属性条件的商品id */ { if (is_numeric($v) && $v !=0 &&isset($cat_filter_attr[$k])) { $sql = $ext_sql . b.attr_value = a.attr_value and b.attr_id = . $cat_filter_attr[$k] . and a.goods_attr_id = . $v; $ext_group_goods = $globals['db']->getcolcached($sql); $ext .= ' and ' . db_create_in($ext_group_goods, 'g.goods_id'); } } } return $all_attr_list; } }
调用的时候
$all_attr_list = get_my_class(22);$smarty->assign('woshi', $all_attr_list);
