• 257阅读
  • 1回复

ECSHOP只有登录用户才能查看商品

楼层直达
我们在访问商城时,要使得只有登陆后才可以查找到商品的详情页,这样做总感觉有点太封闭了,这就有点有点类似于discuz论坛一样,只有当注册用户登陆后才能够进行发言,感觉有点不太好,不过也有些老用户就是需要这样的要求,因此可以进行研究一下的,如果想要在ecshop中实现只有登陆后才能查看商品详情页面还是较简单的。那么如何实现ecshop如何实现只有登录用户才能访问商品详情内容,下面ECSHOP插件网和大家说下简单的方法? xi(\=LbhY  
打开/themes/default/goods.dwt文件,找到如下代码 mA+:)?e5~  
<!--当前位置 end--> ^.!jD+=I  
下面添加如下代码 _<F)G,=  
{if $smarty.session.user_id gt 0} -m%`Di!E  
再继续找到如下: j/d}B_2  
<!--友情链接 end--> `IUn{I  
下面添加如下代码 ~E7IU<B  
{else} ,dCEy+  
<div class="block">您未登录,只有登录用户才有权查看!</div> |2u=3#Jp  
{/if} ujX; wGje  
这样修改以后如果是匿名用户在访问详情页的时候会提示去登录,就可以实现只有登录用户才能查看商品详情,未登录用户无法查看商品详情的效果。
只看该作者 安逸沙发  发表于: 2018-09-30
ecshop根据标签(关键字)调用商品 q376m-+  
aFX=C >M  
1.打开/includes/lib_goods.php文件里加上这段: 4yy>jXDG  
function get_keyword_goods($keyword = '') ~ D j8 z+^  
{ ].w4$OJ?  
    $time = gmtime(); A4x]Qh3OO  
    $order_type = $GLOBALS['_CFG']['recommend_order']; zZPO&akB"  
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . pK>N-/?a  
            "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". S6DKREO  
            "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " . ~g]Vw4pv  
            "g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " . gh]cXuph  
            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . *w`sM%]Rq  
            'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . ,]F,Uu_H7  
            "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". tCH!my_  
            "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". <dtGK~_  
            'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . l_d5oAh   
            " AND g.keywords LIKE '%$keyword%' " ; $ bR~+C  
    $sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd'; k1~&x$G  
    $result = $GLOBALS['db']->getAll($sql); Ax7[;|2  
    $goods = array(); (y~TL*B  
    foreach ($result AS $idx => $row) $Ds2>G4c  
    { %ntRG !  
        if ($row['promote_price'] > 0) +'HqgSPyb  
        { /W<;Z;zk  
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); hL{KRRf>  
            $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; g}cq K  
        } FvjPdN/L?R  
        else @qAS*3j  
        { _]H&,</  
            $goods[$idx]['promote_price'] = ''; 9W2Vo [(  
        } HIZe0%WPw  
        $goods[$idx]['id']           = $row['goods_id']; 2E'UZ m  
        $goods[$idx]['name']         = $row['goods_name']; W/h[A3 `3N  
        $goods[$idx]['brief']        = $row['goods_brief']; + cN8Y}V  
        $goods[$idx]['brand_name']   = $row['brand_name']; _-g&PXH  
        $goods[$idx]['goods_style_name']   = add_style($row['goods_name'],$row['goods_name_style']); XXa|BZ1RX  
        $goods[$idx]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; [{,1=AB  
        $goods[$idx]['short_style_name']   = add_style($goods[$idx]['short_name'],$row['goods_name_style']); pW3^X=6  
        $goods[$idx]['market_price'] = price_format($row['market_price']); 4^:=xL  
        $goods[$idx]['shop_price']   = price_format($row['shop_price']); .?$gpM?i  
        $goods[$idx]['thumb']        = get_image_path($row['goods_id'], $row['goods_thumb'], true); /%^#8<=|U  
        $goods[$idx]['goods_img']    = get_image_path($row['goods_id'], $row['goods_img']); Cw&KVw*  
        $goods[$idx]['url']          = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); x[e<} 8'$(  
    } 7@W>E;go  
    return $goods; Jln:`!#fDf  
} ZbKg~jdF  
2.在需要调用商品的页面php文件(一般是index.php)里在 assign_dynamic('index'); 之前写上这段 p5*EA x  
$smarty->assign( 'ecshop_vc',      get_keyword_goods('商城首页')); GTHt'[t@;  
其中,商城首页是我在商品的“其他信息”-“商品关键词”一栏中填写的用于调用的关键词 gs`q6 f%(  
3. 在需要调用商品的dwt或lbi中用foreach就可以调啦 Wx#;E9=Im  
<!--{foreach from=$ecshop_vc item=goods}--> {_*yGK48n  
<!--{/foreach}-->
快速回复

限100 字节
安逸网提示:如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
认证码:
上一个 下一个