Ecshop的商品筛选功能实现分析之一(主要对category.php进行分析)
2014-09-16 17:42
645 查看
一、首先,说明一下为什么要对category.php文件进行分析。
(1)原因如下:
①个人对商城类商品筛选功能的实现比较好奇;②对商城中关于商品的数据表设计比较感兴趣。(该功能涉及到与数据库的交互,而且与数据库中数据表的设计好坏有一定的联系);
③多条件(属性)筛选功能在现今的很多网站都需要用到,很广泛(如:一般商城网、团购网、房产网、信息分类网站等等)。
(2)希望达到的目的是:
①能够对多条件筛选功能有一个初步的认识。(起码自己做,也能够快速实现吧);②对多条件筛选的实现中,数据库该如何去设计才会更优化和更合理些(参考前人的经验);
③对多条件筛选中的一些策略或者是技巧,能有一个了解(会总结几点)
二、然后,我们首先看一下现在需求是如何的?(多条件筛选,请参考京东、苏宁、国美等)
①京东商城的商品筛选功能(截图):1 //向模板,载入一些前台,必备的变量和常量 2 assign_template('c', array($cat_id)); 3 4 //RETURN:Array ( [title] => 夏新_GSM手机_手机类型_ECSHOP演示站 - Powered by ECShop [ur_here] => 首页 > 手机类型 > GSM手机 > 夏新 ) 5 $position = assign_ur_here($cat_id, $brand_name); 6 7 $smarty->assign('page_title', $position['title']); // 页面标题 8 $smarty->assign('ur_here', $position['ur_here']); // 当前位置 9 10 $smarty->assign('categories', get_categories_tree($cat_id)); // 分类树 11 $smarty->assign('helps', get_shop_help()); // 网店帮助 12 $smarty->assign('top_goods', get_top10()); // 销售排行 13 $smarty->assign('show_marketprice', $_CFG['show_marketprice']); //是否显示市场价 14 $smarty->assign('category', $cat_id); 15 $smarty->assign('brand_id', $brand); 16 $smarty->assign('price_max', $price_max); 17 $smarty->assign('price_min', $price_min); 18 $smarty->assign('filter_attr', $filter_attr_str); 19 $smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? "feed-c$cat_id.xml" : 'feed.php?cat=' . $cat_id); // RSS URL 20 21 if ($brand > 0) { 22 $arr['all'] = array('brand_id' => 0, 23 'brand_name' => $GLOBALS['_LANG']['all_goods'], 24 'brand_logo' => '', 25 'goods_num' => '', 26 'url' => build_uri('category', array('cid'=>$cat_id), $cat['cat_name']) 27 ); 28 } else { 29 $arr = array(); 30 } 31 32 $brand_list = array_merge($arr, get_brands($cat_id, 'category')); 33 $smarty->assign('data_dir', DATA_DIR); //网站data目录 34 $smarty->assign('brand_list', $brand_list); 35 $smarty->assign('promotion_info', get_promotion_info()); //获取推荐信息 36 37 /* 调查 */ 38 $vote = get_vote(); 39 if (!empty($vote)) { 40 $smarty->assign('vote_id', $vote['id']); 41 $smarty->assign('vote', $vote['content']); 42 } 43 44 //获取最热销、推荐和最热卖商品 45 $smarty->assign('best_goods', get_category_recommend_goods('best', $children, $brand, $price_min, $price_max, $ext)); 46 $smarty->assign('promotion_goods', get_category_recommend_goods('promote', $children, $brand, $price_min, $price_max, $ext)); 47 $smarty->assign('hot_goods', get_category_recommend_goods('hot', $children, $brand, $price_min, $price_max, $ext)); 48 //获取该前状态下,商品的数量 49 $count = get_cagtegory_goods_count($children, $brand, $price_min, $price_max, $ext); 50 //最大页数 51 $max_page = ($count> 0) ? ceil($count / $size) : 1; 52 if ($page > $max_page) { 53 $page = $max_page; 54 } 55 56 //获取该栏目下的所有商品 57 $goodslist = category_get_goods($children, $brand, $price_min, $price_max, $ext, $size, $page, $sort, $order); 58 59 //判断选择了列表还是图片方式显示方式 60 if($display == 'grid') { 61 if(count($goodslist) % 2 != 0) { 62 $goodslist[] = array(); 63 } 64 } 65 66 $smarty->assign('goods_list', $goodslist); //注入商品列表 67 $smarty->assign('category', $cat_id); //注入分类id 68 $smarty->assign('script_name', 'category'); //注入该脚本的名称 69 70 assign_pager('category', $cat_id, $count, $size, $sort, $order, $page, '', $brand, $price_min, $price_max, $display, $filter_attr_str); // 分页 71 assign_dynamic('category'); // 动态内容 72 } 73 $smarty->display('category.dwt', $cache_id);
View Code
说明:以上的代码中,都有对其实现方法,有非常具体的说明,详情请见代码的备注。
总结:分析都最后,其实我有些些失望了,因为这个所谓多条件搜索功能的实现,并不算是很复杂,很高深的东西,都比较简单(和我的想法差不多)。
不过,我也学到了一些东西,具体如下:
① 对Ecshop商品主要数据表的设计有了了解。(下一篇会简单介绍)
② 原来这里的要对商品的那些属性进行筛选,并不是程序自动处理,而是管理员后台指定的。
③ 价格区间的计算,是按照一定的算法计算出来的,比较智能,但数字不太好看(另外一种策略,是自己后台为每一个商品分类,都指定一个价格区间,也是可以的。)
④ 品牌、价格区间和属性,都是按照一定的原则从数据库抽取出来的。即,这些说有的分类或者属性下,必须是有商品的,才会把它获取出来。比如,如果颜色为黑色的属性下面是没有任何商品的,那么黑色这个属性,就不应该显示出来。其他依次类推。
⑤ 对于一些较为复杂的mysql语句查询,有了一些了解(希望不断提高啦。。)
以上,是小弟做的一些小小的分析和总结,我经验还不丰富啊,有哪一些不对的地方和不足,希望大家指正,我会虚心学习和接受,谢谢啦!!
相关文章推荐
- 【PHP开源产品】Ecshop的商品筛选功能实现分析之一(主要对category.php进行分析)
- 大型PHP电商网站商品秒杀功能实现思路分析
- 大型PHP电商网站商品秒杀功能实现思路分析 技术角度称为:高可用 高并发
- 用php实现类似淘宝,拍拍,易趣的最近浏览商品的功能模型代码
- 类似京东的商品筛选功能的实现,电子商城的产品筛选功能是怎么实现的?
- Php中文件下载功能实现超详细流程分析
- 类似京东的商品筛选功能的实现,电子商城的产品筛选功能是怎么实现的?
- Php中文件下载功能实现超详细流程分析
- 用js进行url编码后用php反解以及用php实现js的escape功能函数总结
- 解析PHP留言本模块主要功能的函数说明(代码可实现)
- ecshop商品详细描述页,批量上传图片功能实现
- 用js进行url编码后用php反解以及用php实现js的escape功能函数总结
- 银行调度系统主要实现功能的分析及代码实现
- CSS3转换功能transform主要属性值分析及实现分享
- Php如何实现下载功能超详细流程分析
- 类似于京东商城等的商品分类搜索筛选功能实现
- 类似于京东商城等的商品分类搜索筛选功能实现
- PHP实现下载功能之流程分析
- ecshop实现商品列表页属性筛选区品牌筛选以LOGO形式展示
- Php如何实现下载功能超详细流程分析