Maison > Article > interface Web > ecshop商品列表页面增加按销量排序_html/css_WEB-ITnose
STEP1:在表“ecs_goods”添加字段:salesnum(注:自定义字段名)
STEP2:打开根目录下文件:flow.php
找到下面的代码:
/* 插入订单商品 */
$sql = “INSERT INTO ” . $ecs->table(’order_goods’) . “( ” .
“order_id, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, “.
“goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id) “.
” SELECT ‘$new_order_id’, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, “.
“goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id”.
” FROM ” .$ecs->table(’cart’) .
” WHERE session_id = ‘”.SESS_ID.”‘ AND rec_type = ‘$flow_type’”;
$db->query($sql);
在这段代码的下面,添加如下代码:
/* 插入商品表的salesnum 字段,统计销量排行 */
$sql = "update " .$GLOBALS['ecs']->table('goods') . " AS a, ".$GLOBALS['ecs']->table('cart') . " AS b ".
" set a.salesnum= a.salesnum + b.goods_number".
" WHERE a.goods_id=b.goods_id AND b.session_id = '".SESS_ID."' AND b.rec_type = '$flow_type'";
$db->query($sql);
STEP3:打开文件:default\library\goods_list.lbi,找到下面的代码:
ASCDESC#goods_list”>{$pager.order}default.gif” alt=”{$lang.sort.last_update}”>
在上面那段代码的下面添加:
ASCDESC#goods_list”>{$pager.order}default.gif” alt=”按销量排行”>
两段代码的区别,自己去分析看看吧。
STEP4:打开文件:category.php,找到如下代码:
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array(’goods_id’, ’shop_price’, ‘last_update’)))
修改为:
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array(’goods_id’, ’shop_price’, ‘last_update’,’salesnum’)))