ecshop根据标签(关键字)调用商品 uA%F0oM
N *n?hN
1.打开/includes/lib_goods.php文件里加上这段: *q Ins/@
function get_keyword_goods($keyword = '') O}lqY?0*
{ VD=F{|^
$time = gmtime(); u/?;J1z:
$order_type = $GLOBALS['_CFG']['recommend_order']; rf&nTDaWI
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . dFpP_U
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". NsSl|m
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " . QlxlT $o}
"g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " . t4iV[xl3F
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . v[?eL0Z
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . :3*0o3C/
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". ]p~,C*UH0
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". \RTX fe-`
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . ch}(v'xv(
" AND g.keywords LIKE '%$keyword%' " ; O7I|<H/gVE
$sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd'; }Rq-IRa'
$result = $GLOBALS['db']->getAll($sql); We#O'm
$goods = array(); 6~Xe$fP(
foreach ($result AS $idx => $row) [PW*|U
{ C{):jH,Rf
if ($row['promote_price'] > 0) 0IjQqI
{ 4;d9bd)A
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); )<jT;cT!&
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; TXQY&7
} ojd/%@+u+Y
else $
p{Q ]|ww
{ yf7p0;$?
$goods[$idx]['promote_price'] = ''; 0$l D
} < F Cr
L
$goods[$idx]['id'] = $row['goods_id']; m:~s6c6H
$goods[$idx]['name'] = $row['goods_name']; `+QrgtcEy4
$goods[$idx]['brief'] = $row['goods_brief']; G}\E{VvWh
$goods[$idx]['brand_name'] = $row['brand_name']; |nj%G<
$goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); >g6:{-b^a
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; LE!3'^Zq
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']); fF8g3|p:
$goods[$idx]['market_price'] = price_format($row['market_price']); E7axINca
$goods[$idx]['shop_price'] = price_format($row['shop_price']); sEL[d2oO
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); Jh[fFg]
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); y4Plm.
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); r>`65o
} w.Ft-RXA W
return $goods; z.pP~he
} +B%ZB9
2.在需要调用商品的页面php文件(一般是index.php)里在 assign_dynamic('index'); 之前写上这段 ;
eq^m,oz
$smarty->assign( 'ecshop_vc', get_keyword_goods('商城首页')); h4S,(*V$!
其中,商城首页是我在商品的“其他信息”-“商品关键词”一栏中填写的用于调用的关键词 q?{wRBVVB
3. 在需要调用商品的dwt或lbi中用foreach就可以调啦 k|nv[xY0
<!--{foreach from=$ecshop_vc item=goods}--> 2|Hq[c=~
<!--{/foreach}-->