【第一步】在表“ecs_goods”添加字段:salesnum(注:自定義字段名)
方法:alter table `ecs_goods` ADD `salesnum` int(11) NOT NULL DEFAULT 0;
【第二步】打開根目錄下文件: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);
在這段代碼的下面,添加如下代碼:
/* 2012-08-15 作者嚴微 插入商品表的salesnum 字段,統(tǒng)計銷量排行 */ $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);
【第三步】打開文件:default\library\goods_list.lbi,找到下面的代碼:
<a href="{$script_name}.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/last_update_<!-- {if $pager.sort == 'last_update'} -->{$pager.order}<!-- {else} -->default<!-- {/if} -->.gif" alt="{$lang.sort.last_update}"></a>
【注】改代碼是“更新時間”
在上面那段代碼的下面添加:[紅色區(qū)是圖片的名稱,對應(yīng)做上該命名的圖片即可]
<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} -->#goods_list"><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')))
Copyright © 2009-2019 Ywcms.Com All Right Reserved. 湘ICP備16006489號-2