ECSHOP 商品页详情页 添加同类随机商品
时间:2024年01月31日
/来源:网络
/编辑:佚名
1,根目录下找到goods.php文件
找到代码 $smarty->assign('properties', $properties['pro']); // 商品属性
在上面加代码 $smarty->assign('category_related_random_goods', category_related_random_goods($goods['cat_id'])); // 同分类随机商品
再在最底部添加上 随机同类商品的函数, 以下代码
复制代码
/*同分类下随机推荐商品*/
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 就是显示个数的
找到代码 $smarty->assign('properties', $properties['pro']); // 商品属性
在上面加代码 $smarty->assign('category_related_random_goods', category_related_random_goods($goods['cat_id'])); // 同分类随机商品
再在最底部添加上 随机同类商品的函数, 以下代码
复制代码
/*同分类下随机推荐商品*/
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 就是显示个数的
新闻资讯 更多
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法