ECSHOP商品详细页显示/获取属性库存
作者:我就是个世界
发表于:2013-11-01
先看效果图:
[img][attach]447[/attach][/img]
[img][attach]448[/attach][/img]
这个是我修改的,可以动态改变商品单价及总价
方法如下(感谢[url=http://www.xc35.net/post/13.html]星辰博客[/url]):
includes\lib_goods.php 行 612开始的 [separator]
[code]
/**
* 获得商品的属性和规格*
* @access public
* @param integer $goods_id
* @return array
*/
function get_goods_properties($goods_id)
{
/* 对属性进行重新排序和分组 */
$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 " .
",p.product_sn,p.product_number " ./* 这一行是我加的*/
'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('products') . ' AS p ON g.goods_attr_id = p.goods_attr ' . /* 这一行也是我加的*/
"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'];
$arr['spe'][$row['attr_id']]['values'][] = array(
'label' => $row['attr_value'],
'price' => $row['attr_price'],
'format_price' => price_format(abs($row['attr_price']), false),
'id' => $row['goods_attr_id'],
'product_sn' => $row["product_sn"],/* 这一行是我加的*/
'product_number' => $row["product_number"],/* 这一行是我加的*/
);
}
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;
}
[/code]
我只加了四行
模板 goods.dwt 调用:
[code]货号 : {$value.product_sn} 库存 : {$value.product_number}[/code]
[img][attach]447[/attach][/img]
[img][attach]448[/attach][/img]
这个是我修改的,可以动态改变商品单价及总价
方法如下(感谢[url=http://www.xc35.net/post/13.html]星辰博客[/url]):
includes\lib_goods.php 行 612开始的 [separator]
[code]
/**
* 获得商品的属性和规格*
* @access public
* @param integer $goods_id
* @return array
*/
function get_goods_properties($goods_id)
{
/* 对属性进行重新排序和分组 */
$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 " .
",p.product_sn,p.product_number " ./* 这一行是我加的*/
'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('products') . ' AS p ON g.goods_attr_id = p.goods_attr ' . /* 这一行也是我加的*/
"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'];
$arr['spe'][$row['attr_id']]['values'][] = array(
'label' => $row['attr_value'],
'price' => $row['attr_price'],
'format_price' => price_format(abs($row['attr_price']), false),
'id' => $row['goods_attr_id'],
'product_sn' => $row["product_sn"],/* 这一行是我加的*/
'product_number' => $row["product_number"],/* 这一行是我加的*/
);
}
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;
}
[/code]
我只加了四行
模板 goods.dwt 调用:
[code]货号 : {$value.product_sn} 库存 : {$value.product_number}[/code]
请发表您的评论