ECSHOP商品详情页相关商品随机显示方法

2016-07-07 16:02 来源:www.chinab4c.com 作者:ecshop专家

ECSHOP商品详情页优化真是不易啊,最近想起来了这个办法,随机显示相关商品,网上找了N多教程,也没有弄成,最后看到一位高手发布的修改商品列表页产品随机显示的教程,修改了一下,竟然实现了,商品详情页相关商品的随机显示.

演示地址: http://www.tingmeiyunchan.com/goods-344.html

废话不讲了,看教程吧,其实非常简单.

找到 ecshop根目录 goods.php

默认模板第288行左右找到:
  1. * 获得指定商品的关联商品
  2. *
  3. * @accesspublic
  4. * @paraminteger$goods_id
  5. * @returnarray
  6. */
  7. function get_linked_goods($goods_id)
  8. {
  9. $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .
  10. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
  11. 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .
  12. 'FROM ' . $GLOBALS['ecs']->table('link_goods') . ' lg ' .
  13. 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = lg.link_goods_id ' .
  14. "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  15. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  16. "WHERE lg.goods_id = '$goods_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
  17. "LIMIT " . $GLOBALS['_CFG']['related_goods_number'];
  18. $res = $GLOBALS['db']->query($sql);
复制代码
搜索大约在293行:

替换为下方代码即可.
  1. * 获得指定商品的关联商品
  2. *
  3. * @accesspublic
  4. * @paraminteger$goods_id
  5. * @returnarray
  6. */
  7. function get_linked_goods($goods_id)
  8. {
  9. $adcode=1;
  10. $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .
  11. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
  12. 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .
  13. 'FROM ' . $GLOBALS['ecs']->table('link_goods') . ' lg ' .
  14. 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = lg.link_goods_id ' .
  15. "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  16. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  17. "WHERE lg.goods_id = '$goods_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
  18. $sql .= $adcode == 0 ? " $order" : " ORDER BY RAND()".
  19. "LIMIT " . $GLOBALS['_CFG']['related_goods_number'];
  20. $res = $GLOBALS['db']->query($sql);
复制代码

回答:
支持,!

谢楼主了!

vancl模板没成功,估计是不是要改模板内文件调整型内衣

收起

没有成功,楼主自忆的好像也不行?????www.111golf.com求解释!

也是vancl模板没成功

这个不错,要顶。

相关商品随机显示有什么好处呀??不太明白

/**
* 获得指定商品的关联商品
*
* @accesspublic
* @paraminteger$goods_id
* @returnarray
*/
function get_linked_goods($goods_id)
{
$adcode=1;
$sql = 'SELECT goods_id, goods_name, goods_thumb, goods_img, shop_price AS org_price, ' .
'market_price, promote_price, promote_start_date, promote_end_date ' .
'FROM ' . $GLOBALS['ecs']->table('goods').
" WHERE is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 ".
$sql .= " ORDER BY RAND()".
" LIMIT " . $GLOBALS['_CFG']['related_goods_number'];
$res = $GLOBALS['db']->query($sql);
我改成这样,可以了

收起
手气手气

这个真的不错的……

我觉得这个是很好的

挺实用的功能啊