PHP7中文手册2018 带注释 最新chm版
1.在ecshop程序goods.php页面最下面加入这两个函数
function get_buy_sum($goods_id)
{
$sql = 'SELECT IFNULL(SUM(g.goods_number), 0) ' .
'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' .
$GLOBALS['ecs']->table('order_goods') . ' AS g ' .
"WHERE o.order_id = g.order_id " .
"AND o.order_status = '" . OS_CONFIRMED . "' " .
"AND o.shipping_status " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) .
" AND o.pay_status " . db_create_in(array(PS_PAYED, PS_PAYING)) .
" AND g.goods_id = '$goods_id'";
return $GLOBALS['db']->getOne($sql);
}
function get_comment_num($goods_id) {
$sql= "select count(*) from ".$GLOBALS['ecs']->table('comment')." where id_value='".$goods_id."' AND status = 1";
return $GLOBALS['db']->getOne($sql);
}
2.在ecshop程序goods.php中找到
$smarty->display('goods.dwt', $cache_id);在它之前加上如下代码
$smarty->assign('buy_num',get_buy_sum($goods_id));
$smarty->assign('comment_num',get_comment_num($goods_id));
3.ecshop中goods.dwt模板中加这个,大概在221行
<!-- {if $buy_num} 已出售量-->
<li class="clearfix">
<dd>
<strong>累计售出:</strong>{$buy_num}
</dd>
</li>
<!--{/if}-->
<!-- {if $comment_num} 评论数量-->
<li class="clearfix">
<dd>
<strong>评论数量:</strong><a href="#comment">{$comment_num}</a>
</dd>
</li>
<!--{/if}-->
!!转载出自是以上代码,亲自实践发现只需要写上{$buy_num}和{$comment_num}就可以调出,无需<!--{if}-->以内的代码
转载请注明:同盟者网络 http://blog.sina.com.cn/tomener
PS:实践发现此方法只实用于goods页面,其他页面无法调用,往后继续找到category页面的调用已售数量的方法
转载请注明:谷谷点程序 » ecshop增加已售数量和评论数量