轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 ECShop网店 查看主题

ECSHOP商品详情页添加调用同类随机商品

发布者: lhb2003 | 发布时间: 2019-2-9 02:26| 查看数: 5236| 评论数: 1|帖子模式

通过以下教程可以实现,在商品详情页中调用显示同类的随机商品
1,根目录下找到goods.php文件
查找代码:
$smarty->assign('properties',          $properties['pro']);                              // 商品属性


在上面一行添加以下代码:
$smarty->assign('category_related_random_goods',       category_related_random_goods($goods['cat_id'])); // 同分类随机商品


接着还在goods.php文件的最低部也就是 ?>前添加以下代码:

/*同分类下随机推荐商品*/
function category_related_random_goods($category_id)
{
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".
            "g.is_delete = 0 AND g.cat_id=$category_id ";
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
                "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
                'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
            'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
                "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
            "WHERE $where ORDER BY rand() limit 12";
    $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;
}
2、新建模板文件 category_related_random_goods.lbi ,代码如下





        Related Products


        
        

                      
            

  •         


  •         
            {$lang.promote_price}{$category_related_random_goods_data.formated_promote_price}
            
            {$lang.shop_price}{$category_related_random_goods_data.shop_price}

            
            

        









样式可以自己定义
把category_related_random_goods.lbi文件复制到 /themes/你使用的模板/library/   文件夹里



3,找到  /themes/你使用的模板/goods.dwt  文件

在适当的位置加上



一般加在


下面或者上面,和其他模块是同理的

PS: googs.php 里 ORDER BY rand() limit 12   这个代码 12 就是显示个数的

最新评论

烧饼铺掌柜的 发表于 2022-7-17 19:29
开端和源代码

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表