ecshop模板网站商品页详情页添加同类随机商品

2016-06-19 0 4,310

网站商品页详情页添加同类随机商品!在商品页详情页添加同类随机商品,能起到更好的展示效果,美观的客户体验,加让系统更方便搜索引擎抓取。

1、ecshop根目录下找到goods.php文件

找到ecshop代码

$smarty->assign('properties',          $properties['pro']);                              // 商品属性

在上面加代码

$smarty->assign('category_related_random_goods',       category_related_random_goods($goods['cat_id'])); // 同分类随机商品

再在ecshop最底部添加上 随机同类商品的函数, 以下代码

/*同分类下随机推荐商品*/
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();//www.dhaomu.com
    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、新建ecshop模板文件 category_related_random_goods.lbi

代码如下

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- {if $category_related_random_goods} -->
 <div class="box">
        <h3>Related Products</h3>
        <div>
        <ul>
        <!--{foreach from=$category_related_random_goods item=category_related_random_goods_data}-->           
        <li class="li1" style="float:left; margin-bottom:20px;"><a href="{$category_related_random_goods_data.url}" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ><img src="{$category_related_random_goods_data.goods_thumb}" alt="{$category_related_random_goods_data.goods_name}"/></a></li>
        <li class="li2" style="float:left; margin-bottom:20px;"><a href="{$category_related_random_goods_data.url}" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  title="{$category_related_random_goods_data.goods_name}">{$category_related_random_goods_data.short_name}</a><br />
        <!-- {if $category_related_random_goods_data.promote_price neq 0} -->
        {$lang.promote_price}<font class="f1">{$category_related_random_goods_data.formated_promote_price}</font>
        <!-- {else} -->
        {$lang.shop_price}<font class="f1">{$category_related_random_goods_data.shop_price}</font>
        <!-- {/if} --></li>
        <!--{/foreach}-->
        </ul>
        </div>
 </div>
<div class="blank5"></div>
<!-- {/if} -->

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

3、ecshop找到 /themes/你使用的商城模板/goods.dwt 文件

加上

<!-- #BeginLibraryItem "/library/category_related_random_goods.lbi" --><!-- #EndLibraryItem -->

加在

 <!-- #BeginLibraryItem "/library/goods_tags.lbi" --><!-- #EndLibraryItem -->

其他ecshop模块是同理的

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

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明: 本站仅提供资源学习下载,资源费用仅为赞助站长的整理费,不代表资源自身价值也不包含任何服务。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
本站提供的资源来自网络,版权争议与本站无关,所有内容及软件的文章仅限用于学习和研究目的。
如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。侵删请致信E-mail:duhaomu@163.com

浩沐资源网 未分类 ecshop模板网站商品页详情页添加同类随机商品 https://www.haomu.top/31441.html

相关文章

发表评论
暂无评论
  • 0 +

    访问总数

  • 0 +

    会员总数

  • 0 +

    文章总数

  • 0 +

    今日发布

  • 0 +

    本周发布

  • 0 +

    运行天数

你的前景,远超我们想象