ecshop根据标签(关键字)调用商品 `Y4K w
<%S)6cw(3
1.打开/includes/lib_goods.php文件里加上这段: j7kX"nz
function get_keyword_goods($keyword = '') .G!xcQ`?
{ J#F5by%8
$time = gmtime(); :#^qn|{e
$order_type = $GLOBALS['_CFG']['recommend_order']; `HXv_9
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . D~ Y6%9
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". BL16?&RK
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " . -?)^
hbr
"g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " . y2#>a8SRS
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . K!&W} _@l
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . BKg8p]`+
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". x'x5tg
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". w8 :[w
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . <.n,:ir
" AND g.keywords LIKE '%$keyword%' " ; :kR>wX
$sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd'; iF^qbh%%E
$result = $GLOBALS['db']->getAll($sql); \(i'i C
$goods = array(); HfVHjF)
foreach ($result AS $idx => $row) 2j%=o?me^p
{ Lxp}o7>K
if ($row['promote_price'] > 0) *pwkv7Zh
{ U*=E(l
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
^^"zjl*^
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; @\ y{q;
} P!+Gwm{
else hE {";/}J
{ :1*E5pX0n
$goods[$idx]['promote_price'] = ''; ; R+>}6
} =6dAF"b)
$goods[$idx]['id'] = $row['goods_id']; 1- s(v)cxh
$goods[$idx]['name'] = $row['goods_name']; (SRY(q
$goods[$idx]['brief'] = $row['goods_brief']; 61H_o7XXk
$goods[$idx]['brand_name'] = $row['brand_name']; !ddyJJ^a
$goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); ({j8|{)+
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; Q)0KYKD+@
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']); @G2# Z
$goods[$idx]['market_price'] = price_format($row['market_price']); X=#us7W}
$goods[$idx]['shop_price'] = price_format($row['shop_price']); v>wN
O
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); 8+[Vo_]
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); 0fewMS*
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); Dq<la+VlO
} 4 -tC=>>wc
return $goods; ~g=&wT11
} R0INpF';
2.在需要调用商品的页面php文件(一般是index.php)里在 assign_dynamic('index'); 之前写上这段 gFp3=s0~
$smarty->assign( 'ecshop_vc', get_keyword_goods('商城首页')); !-OZ/^l|O`
其中,商城首页是我在商品的“其他信息”-“商品关键词”一栏中填写的用于调用的关键词 qt@/
3. 在需要调用商品的dwt或lbi中用foreach就可以调啦 AT1cN1:4?
<!--{foreach from=$ecshop_vc item=goods}--> D@La-K*5
<!--{/foreach}-->