您现在的位置是:首页 > 教程 > ecshop商城教程ecshop商城教程
ecshop商品详情页添加调用同类随机商品
杨舟察2024-01-18 22:56:33ecshop商城教程已有人查阅
导读通过以下教程可以实现,在ECSHOP商品详情页中调用显示同类的随机商品1,根目录下找到goods.php文件查找代码:$smarty->assign('p
通过以下教程可以实现,在ECSHOP商品详情页中调用显示同类的随机商品
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 ,
代码如下
<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}"><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}" 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,找到 /themes/你使用的模板/goods.dwt 文件
在适当的位置加上
<!-- #BeginLibraryItem "/library/category_related_random_goods.lbi" --><!-- #EndLibraryItem -->
一般加在 <!-- #BeginLibraryItem "/library/goods_tags.lbi" --><!-- #EndLibraryItem -->
下面或者上面,和其他模块是同理的
PS: googs.php 里 ORDER BY rand() limit 12 这个代码 12 就是显示个数的
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 ,
代码如下
<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}"><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}" 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,找到 /themes/你使用的模板/goods.dwt 文件
在适当的位置加上
<!-- #BeginLibraryItem "/library/category_related_random_goods.lbi" --><!-- #EndLibraryItem -->
一般加在 <!-- #BeginLibraryItem "/library/goods_tags.lbi" --><!-- #EndLibraryItem -->
下面或者上面,和其他模块是同理的
PS: googs.php 里 ORDER BY rand() limit 12 这个代码 12 就是显示个数的
本文标签:
很赞哦! ()
相关文章
随机图文
-
ecshop删除Powered by ecshop版权实例
去掉头部TITLE部分的ECSHOP演示站 Powered by ecshop 前者在后台商店设置 - 商店标题修改 后者打开includes/lib_main.php -
ecshop商品订单只要有一个包邮商品,整个商品订单全部包邮
ecshop商品订单只要有一个包邮商品,整个商品订单全部包邮1. includes/lib_order.php搜索“查看购物车中是否全为免运费商品,若是则 -
ecshop虚拟商品虚拟卡编辑和使用方法
您可以按照“虚拟卡分类”、“品牌”、“推荐类型”、“关键字”(“虚拟卡名称”或“货号”的一部分)进行查询。可以使用某个条件或某几个条件的组 合进行查询。 -
ecshop调用指定dedecms织梦栏目文章列表
系统:dedecms + ecshop 实现步骤: 1.在文章模版goods.dwt添加一个新的库文件dede_articles.lbi themes/default/goods.dwt
留言与评论 (共有 条评论) |