ECSHOP首页调用指定扩展分类商品
发布时间:12/03 来源: 浏览:
关键词:
因为一些原因需要在网站首页调用扩展分类的商品,找了一天没找到具体方法,所以决定自己动手丰衣足食,现将此方法分享给大家
1.在后台给商品添加扩展分类
2.查看该扩展分类的cat_id
3.includes\lib_goods.php,添加方法
[php] view plaincopy
- function index_appoint_goods_list($cat_id = '', $num = '')
- {
- $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].' '.
- 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods_cat') . ' AS gc ON gc.goods_id = g.goods_id '.
- 'Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 '.
- $sql .= " AND (gc.cat_id = " . $cat_id ." OR 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))))) .")";
- $sql .= " 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;
- }
4.index.php
[php] view plaincopy
- $smarty->assign('hot_goods', get_recommend_goods('hot')); // 热点文章
下,添加
[php] view plaincopy
- $smarty->assign('index_appoint2_goods', index_appoint_goods_list(2,4)); //(扩展分类id,调用4条数据)
5.themes\default\index.dwt 的相应位置添加
[php] view plaincopy
- <!-- {foreach from=$index_appoint2_goods item=goods name=no}-->
- <div class="line">
- <div class="item">
- <span class=
打赏