ECSHOP商品属性调用到任意页面方法

看到标题有的人觉得这个很复杂,其实这个没那么复杂,直接用下面的方法,就可以在ECSHOP的任意页面调用商品属性。

一)打开includeslib_insert.php文件,在最后面增加一个函数:

function insert_attr($arr)
{
    static $static_res = NULL;
    $aid= isset($arr['aid'])?$arr['aid']:0;
    $gid= isset($arr['gid'])?$arr['gid']:0;
    if($aid==0) return '';
    if ($static_res[$aid][$gid] === NULL)
    {
        if($gid>0)
        {
            $static_res[$aid][$gid] =  $GLOBALS['db']->getOne('select attr_value from ' . $GLOBALS['ecs']->table('goods_attr') . " where attr_id ='$aid' and goods_id='$gid' ");      
        }
        else
        {
            $static_res[$aid][$gid] = $GLOBALS['db']->getOne('select attr_name from ' . $GLOBALS['ecs']->table('attribute') . " where attr_id ='$aid' "); 
        }
    }
    return $static_res[$aid][$gid]; 
}

注意要加在  ?>  的前面。


二)接下来就可以直接在ECSHOP模板中(dwt文件、lib文件皆可)中调用,
调用方法:
{insert name='attr' aid=属性id gid=商品编号} 调用商品的属性值
{insert name='attr' aid=属性id} 调用商品的属性
是不是很简单,经过上面修改代码或增加代码后,就可以在ECSHOP的任意页面调用商品属性了。

赶快试试吧。


原文地址:https://www.cnblogs.com/moqiang02/p/4061315.html