ecshop显示会员对应的等级价格

2009-09-04 13:20 来源:www.chinab4c.com 作者:ecshop专家

     在电子商务系统中,往往需要控制价格的显示。而不同的等级的会员显示不同的价格,就是一个很普通的需求了。下面将结合会员等级和价格的关系,来实现该ecshop显示会员对应的等级价格

1:增加取会员等级价格的函数
function get_user_rank_prices($goods_id, $shop_price)
{
    $sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $shop_price / 100) AS price, r.rank_name, r.discount " .
            'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp ".
                "ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id " .
            "WHERE r.show_price = 1 OR r.rank_id = '$_SESSION[user_rank]'";
    $res = $GLOBALS['db']->query($sql);

    $arr = array();
    while ($row = $GLOBALS['db']->fetchRow($res))
    {

        $arr[$row['rank_id']] = array(
                        'rank_name' => htmlspecialchars($row['rank_name']),
                        'price'     => price_format($row['price']));
    }

    return $arr;
}
2:修改index.php
$best = get_recommend_goods('best');
 $new = get_recommend_goods('new');
 $hot = get_recommend_goods('hot');
 
 if($best){
  foreach($best as $k => $v){
   $up = get_user_rank_prices($v['id'],$v['shopprice']);
   if(in_array($_SESSION[user_rank], array_keys($up))){
    $best[$k]['shop_price'] = $up[$_SESSION[user_rank]][rank_name].":".$up[$_SESSION[user_rank]][price];
   }
  }
 }
 
 if($new){
  foreach($new as $k => $v){
    $up = get_user_rank_prices($v['id'],$v['shopprice']);
    if(in_array($_SESSION[user_rank], array_keys($up))){
     $new[$k]['shop_price'] = $up[$_SESSION[user_rank]][rank_name].":".$up[$_SESSION[user_rank]][price];
    }
  }
 }
 
 if($hot){
  foreach($hot as $k => $v){
    $up = get_user_rank_prices($v['id'],$v['shopprice']);
    if(in_array($_SESSION[user_rank], array_keys($up))){
     $hot[$k]['shop_price'] = $up[$_SESSION[user_rank]][rank_name].":".$up[$_SESSION[user_rank]][price];
    }
   }
 }
 
 
    $smarty->assign('best_goods',      $best );    // 推荐商品
    $smarty->assign('new_goods',       $new);     // 最新商品
    $smarty->assign('hot_goods',       $hot);     // 热点文章

3:get_recommend_goods函数中。需要加一个值。
$goods[$idx]['shopprice']   = $row['shop_price'];用来计算等级价格

 相关文章 :

 让ecshop首页的价格显示对

 分析ecshop会员等级

 ecshop2.6.2会员等级分析

ecshop评论修改以及评论等

 

来源:中国B4C电子商务