您的位置:首页 > 其它

商品详情页面属性价格显示其对应价格

2014-05-26 07:53 197 查看
ecshop默认的商品属性显示的是加多少钱

第一步:在lib_goods.php中找到

function get_goods_properties 方法

将下面的get_goods_properties方法覆盖掉原来的get_goods_properties方法

/**

* 获得商品的属性和规格

*

* @access public

* @param integer $goods_id

* @return array

*/

//yyy修改start

function get_goods_properties($goods_id , $shop_price=0)

//yyy修改end

{

/* 对属性进行重新排序和分组 */

$sql = "SELECT attr_group ".

"FROM " . $GLOBALS['ecs']->table('goods_type') . " AS gt, " . $GLOBALS['ecs']->table('goods') . " AS g ".

"WHERE g.goods_id='$goods_id' AND gt.cat_id=g.goods_type";

$grp = $GLOBALS['db']->getOne($sql);

if (!empty($grp))

{

$groups = explode("\n", strtr($grp, "\r", ''));

}

/* 获得商品的规格 */

$sql = "SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type, ".

"g.goods_attr_id, g.attr_value, g.attr_price " .

'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .

'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .

"WHERE g.goods_id = '$goods_id' " .

'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';

$res = $GLOBALS['db']->getAll($sql);

$arr['pro'] = array(); // 属性

$arr['spe'] = array(); // 规格

$arr['lnk'] = array(); // 关联的属性

foreach ($res AS $row)

{

$row['attr_value'] = str_replace("\n", '<br />', $row['attr_value']);

if ($row['attr_type'] == 0)

{

$group = (isset($groups[$row['attr_group']])) ? $groups[$row['attr_group']] : $GLOBALS['_LANG']['goods_attr'];

$arr['pro'][$group][$row['attr_id']]['name'] = $row['attr_name'];

$arr['pro'][$group][$row['attr_id']]['value'] = $row['attr_value'];

}

else

{

$arr['spe'][$row['attr_id']]['attr_type'] = $row['attr_type'];

$arr['spe'][$row['attr_id']]['name'] = $row['attr_name'];

//yyy修改start

$arr['spe'][$row['attr_id']]['values'][] = array(

'label' => $row['attr_value'],

'price' => $row['attr_price'],

'format_price' => price_format(abs($row['attr_price']) + $shop_price, false),'id' => $row['goods_attr_id']);//yyy修改end

}

if ($row['is_linked'] == 1)

{

/* 如果该属性需要关联,先保存下来 */

$arr['lnk'][$row['attr_id']]['name'] = $row['attr_name'];

$arr['lnk'][$row['attr_id']]['value'] = $row['attr_value'];

}

}

return $arr;

}

第二步:修改goods.php

首先搜索 $properties = get_goods_properties($goods_id); // 获得商品的规格和属性

将这句话修改为

$properties = get_goods_properties($goods_id, $goods['shop_price']); // 获得商品的规格和属性

第三步:修改模版文件themes/模版名称/goods.dwt

搜索{$lang.plus} 和 {$lang.minus} 将搜索出来的这两个变量全部删掉

(说明:不用改原来的数据。不过后台添加商品的时候还是要将属性的价钱编辑为加多少钱。比如原价是160 2磅是300 那么2磅对应的价格设置为140)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: