AB模板网:专注于dede模板,织梦源码,织梦模板,网站模板,dedecms模板,网站源码,dedecms教程以及各类手机网站模板和企业网站模板分享.
用户名:
密码:
注册

织梦模板

网站模板搜索
VIP

ecshop商品详情页增加已售商品数量和评论数量的方法

www.adminbuy.cn / 2015-12-15
1.打开 goods.php 文件,在此文件最下面加入如下两个函数
function get_buy_sum($goods_id)
{
    $sql = 'SELECT INULLSUM(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= "sel ect count(*)  from ".$GLOBALS['ecs']->table('comment')." where id_value='".$goods_id."'  AND status = 1";
     return $GLOBALS['db']->getOne($sql);
}


2.继续修改 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.打开 /themes/模板文件夹/goods.dwt 文件,在需要的地方加入如下代码
<!-- {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}-->
本文由AB模板网:织梦模板整理发布,转载请说明出处:http://www.adminbuy.cn
首页 免费模板 VIP专区 会员中心
收缩