ecshop文章页关联商品显示商品简单描述
2016-09-07 22:03 来源:www.chinab4c.com 作者:ecshop专家
chinab4c在给客户制作ecshop时候,发现文章内关联商品都比较简洁,若是能在关联商品的标题下面显示简单的产品描述,那样会比较好看。 如下图:
chinab4c研究出如下方法: 找到 ecshop根目录文件article.php 获得文章关联的商品 这个定义函数: 原是:
/** * 获得文章关联的商品 * * @access public * @param integer $id * @return array */ function article_related_goods($id) { $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' . 'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' ga ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = ga.goods_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". "WHERE ga.article_id = '$id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0"; $res = $GLOBALS['db']->query($sql);
$arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; $arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']); $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
if ($row['promote_price'] > 0) { $arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']); } else { $arr[$row['goods_id']]['promote_price'] = 0; } }
return $arr; }
修改成:
/** * 获得文章关联的商品 * * @access public * @param integer $id * @return array */ function article_related_goods($id) { $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.goods_brief, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' . 'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' ga ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = ga.goods_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". "WHERE ga.article_id = '$id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0"; $res = $GLOBALS['db']->query($sql);
$arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; $arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
$arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']); $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
if ($row['promote_price'] > 0) { $arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']); } else { $arr[$row['goods_id']]['promote_price'] = 0; } }
return $arr; }
红色为增加部分! 在模板库:goods_related.lbi 相应位置出入: {$releated_goods_data.goods_brief}。搞定! chinab4c原创,转载请注明网址! (责任编辑:chinab4c) |
最近更新
常用插件
- ecshop2.7.2生成虚拟订单2.
以前我们开发过ecshop下的虚拟订单,就是客户在访问的时候,会自动生...
- ecshop2.7.1邮件发送插件
ecshop2.7.1邮件发送插件:该插件主要的开发思想是源于ecshop短信发送系统...
- ecshop二次开发商品购买增
图片1香...
- ecshop最小购买数量控制插
ecshop最小购买数量控制插件,这个插件主要是为我们提供一个十分方便...
- ecshop没登陆情况下订单查
ecshop没登陆情况下订单查询插件,主要是针对ecshop在没有登陆的情况下...