ecshop商品列表多种排序

ecshop商品列表页面的按上架时间、价格、更新时间是默认的,现在需要添加的是按销量排行,但是在商品表里面没有销量的字段,最模板搜集整理提供如下办法:
1:在表“ecs_goods”添加字段:salesnum
2:打开根目录下文件: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);

打开文件:defaultlibrarygoods_list.lbi,找到下面的代码:

<a href=”category.php?category={$category}&display={$pager.display}&brand={$brand_id}&price_min={$price_min}&price_max={$price_max}&filter_attr={$filter_attr}&page={$pager.page}&sort=last_update&order=<!– {if $pager.sort == ‘last_update’ && $pager.order == ‘DESC’} –>ASC<!– {else} –>DESC<!– {/if} –>#goods_list”><img src=”images/lastupdate<!– {if $pager.sort == ‘last_update’} –>{$pager.order}<!– {else} –>default<!– {/if} –>.gif” alt=”{$lang.sort.last_update}”></a>

 

下面添加

<a href=”category.php?category={$category}&display={$pager.display}&brand={$brand_id}&price_min={$price_min}&price_max={$price_max}&filter_attr={$filter_attr}&page={$pager.page}&sort=salesnum&order=<!– {if $pager.sort == ’salesnum’ && $pager.order == ‘DESC’} –>ASC<!– {else} –>DESC<!– {/if} –>#goodslist”><img src=”images/sales<!– {if $pager.sort == ’salesnum’} –>{$pager.order}<!– {else} –>default<!– {/if} –>.gif” alt=”按销量排行”></a>

打开文件: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’)))

 

 

参考网站:

http://www.siqiji.com/show-39.html

http://blog.csdn.net/huangqiaoling/article/details/8076453

http://www.yoozhan.com/ecshop/ecshop-66.html

http://www.soucms.com/CMSjiaocheng/Ecshop/102.html