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

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)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值