让ecshop首页的价格显示对应的等级名称和价格

2009-09-04 11:36 来源:www.chinab4c.com 作者: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);     // 热点文章