EcShop首页显示特定分类的精品新品热销特价等推荐商品

EcShop首页显示特定分类的精品新品热销特价等推荐商品
很多大型的B2C商城都有特定分类专区,该分类下的【分类名称】、【推荐子分类 或 推荐品牌】、【大图片/推荐单品】、【推荐商品】、【促销商品】、【推荐商品/热销排行】等,这是基于SEO及用户体验来开发的。
ECSHOP虽然有类似的功能,并且推荐商品还分[精品]、[新品]、[热销]三类,但灵活性不是很好,首页第一次加载的时候,无论是[精品]、[新品]还是[热销]都不能指定分类,只能不分类别地显示所有。
即使是在分类的设置里面有【设置为首页推荐: 精品 最新 热门】,但这个【设置为首页推荐】的分类的内容不能在首页第一次加载时显示,需要在首页显示后,用ajax读取(触发ajax请求的通常是鼠标onclick/onmouseover事件)。
也就是说这种方法能够指定商品,但不能指定分类
ECSHOP提供了一种可以在首页第一次加载时就显示特定分类下的商品的方法,就是在后台的“设置模板 ”->添加“[+] 分类下的商品”进行设置。这种方式能够指定分类,但不能够指定商品。
要实现指定分类同时指定商品,需要进行二次开发,下面就是夏日博客通过网络上的一些常见解决方法改良的解决方案。此代码优势在只需要填写大类ID,此大类下的所有子类(包括三级分类)的指定类型商品都会调用出来,而且不会在最新发布的商品里出现精品或热销的商品!
1、首先打开includes/lib_goods.php,在最后添加以下函:

/**
* 取指定分类ID及类型的商品信息
* @access public
* @param string $cat_id 分类ID
* @param string $num 显示商品数量
* @param string $cat_type 显示商品类型 new新品,hot热销,best为精品,promote特价
* @return array
*/
function index_get_cat_id_goods_list($cat_id = '', $num = '',$cat_type='')
{
$sql = 'Select g.goods_id, g.cat_id,c.parent_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, " .
"g.is_best, g.is_new, g.is_hot, g.is_promote " .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON c.cat_id = g.cat_id ' .
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
"Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
$sql .= " AND (c.parent_id =" . $cat_id. " or g.cat_id = " . $cat_id ." or g.cat_id ". db_create_in(array_unique(array_merge(array($cat_id), array_keys(cat_list($cat_id, 0, false))))) .")";
if($cat_type!=''){
$sql .=" and is_".$cat_type."=1";
}else{
$sql .=" and is_best=0 and is_new=0 and is_hot=0 and is_promote=0";
}
$sql .= " order by g.goods_id desc LIMIT $num";
$res = $GLOBALS['db']->getAll($sql);
$goods = array();
foreach ($res AS $idx => $row)
{
$goods[$idx]['id'] = $row['article_id'];
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['brand_name'] = $row['brand_name'];
$goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']);
$goods[$idx]['market_price'] = price_format($row['market_price']);
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['thumb'] = empty($row['goods_thumb']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_thumb'];
$goods[$idx]['goods_img'] = empty($row['goods_img']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_img'];
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
}
return $goods;
}

 


2、然后在index.php里设置模板显示数据,其中下面的1为分类ID,5为显示数量
// new新品,hot热销,best为精品,promote特价
$smarty->assign('cat_id1_new_goods', index_get_cat_id_goods_list(1,5));
$smarty->assign('cat_id1_hot_goods', index_get_cat_id_goods_list(1,2,’hot’));
3、最后在首页模板themes/default/index.dwt里循环显示数据


这个代码实例里调用显示的分别为最新商品及热销商品。

转载于:https://www.cnblogs.com/zgzy/p/3805588.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值