如何在ecshop首页显示产品类型属性字段和值

2009-08-31 14:38 来源:www.chinab4c.com 作者:ecshop专家

   ecshop使用的过程中,往往需要将某个特殊的字段,在首页的前台ecshop精品推荐里面,新品里面显示。哪个怎么办呢。

   1:首先在lib_goods.php中增加一个函数。用于读取某个产品下面某个属性字段名称和值

    function get_attribute_value($goods_id, $attri_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_name, g.attr_value " .
            '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' and g.attr_id = $attri_id " .
            'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
    $res = $GLOBALS['db']->getRow($sql);
 
    return $res;
  
}

 2:在ecshop函数get_recommend_goods()中增加一行代码。

  $goods[$idx]['att']          = get_attribute_value($row['goods_id'],213);//取得属性名称和值
 3:修改模板

recommend_new.lbi模板中,增加一行代码

{if $goods.att.attr_name }
    {if $goods.att.attr_value}
        {$goods.att.attr_name}:{$goods.att.attr_value}
     {/if}
     {/if}

用来显示 属性名称/属性值

来源:中国B4C电子商务