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

ecshop默认的商品属性显示的是加多少钱

第一步:在lib_goods.php中找到

function get_goods_properties 方法

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* 获得商品的属性和规格
*
* @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)