ecshop根据标签(关键字)调用商品 8s QQK.N(
!(W[!%
1.打开/includes/lib_goods.php文件里加上这段: b%3Q$wIJ6
function get_keyword_goods($keyword = '') rumAo'T/%
{ AU0$A403
$time = gmtime(); "I5uDFZR&
$order_type = $GLOBALS['_CFG']['recommend_order']; G{F6
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . `ifb<T
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". I_:t}3s
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " . _mw13jcN]
"g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " . Lqg]Fd
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . ;
Zh9^0
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . ~@xT]D!BQ
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". j -#E?&2
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". : @s8?eg
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . YQN.Ohtv*F
" AND g.keywords LIKE '%$keyword%' " ; I9;xz ES
$sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd'; 1d`cTaQ-
$result = $GLOBALS['db']->getAll($sql); }(m1ql
$goods = array(); T&]Na
foreach ($result AS $idx => $row) 0%/,>IR>r
{ n4Vwao/9x
if ($row['promote_price'] > 0) [Uswf3
{ Qr<AV:
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); TFo}\B7
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; >#INEO
} tp@*=*^I
else : g5(HH
{ w"1x=+
$goods[$idx]['promote_price'] = ''; [O(m/
} 3EI]bmi~
$goods[$idx]['id'] = $row['goods_id']; -;vT<G3
$goods[$idx]['name'] = $row['goods_name']; &~'S)Nun
$goods[$idx]['brief'] = $row['goods_brief']; lY8`5Uz
$goods[$idx]['brand_name'] = $row['brand_name']; Ev{MCu1!6
$goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); |g!`\@O
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; >L=;"+B0U&
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']); T<6GcI>A
$goods[$idx]['market_price'] = price_format($row['market_price']); z0
\N{rP&
$goods[$idx]['shop_price'] = price_format($row['shop_price']); o<rsAe
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); ?!y"OrHg
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); Pj&A=
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); d8o ewkiR
} K"w%n[u)
return $goods; @Z q[e
} = ^s$
<
2.在需要调用商品的页面php文件(一般是index.php)里在 assign_dynamic('index'); 之前写上这段 lE'wfUb
$smarty->assign( 'ecshop_vc', get_keyword_goods('商城首页')); M)O[j}N
其中,商城首页是我在商品的“其他信息”-“商品关键词”一栏中填写的用于调用的关键词 >pdnCv_c
3. 在需要调用商品的dwt或lbi中用foreach就可以调啦 =?/&u<
<!--{foreach from=$ecshop_vc item=goods}--> *HeVACxo
<!--{/foreach}-->