ecshop根据标签(关键字)调用商品 Nf%jLK~
*Ny^XQ_ X
1.打开/includes/lib_goods.php文件里加上这段: "/[-U;ck
function get_keyword_goods($keyword = '') w6'o<=
{ &-470Z%/
$time = gmtime(); "O<JVC{m
$order_type = $GLOBALS['_CFG']['recommend_order']; #%il+3J
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . Ny/bNQS
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". #9,!IW]l
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " . gz;( ).{
"g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " . d7g/s'ZHt6
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . U{q6_z|c
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . 9TjAEeU
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". mR,p?[P
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". Ro*$7j0!Hf
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . Ka1
F7b
" AND g.keywords LIKE '%$keyword%' " ; @#c(4}^ <w
$sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd'; =iC5um:
$result = $GLOBALS['db']->getAll($sql); E
j@M\
$goods = array(); B08q/qi
foreach ($result AS $idx => $row) Jvw~b\
{ j
wlmWO6
if ($row['promote_price'] > 0) *YZ'Uy?
{ NDglse
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); Z`v6DfK}
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; %?J\P@
} dt{|bQLu3
else =L{lt9qQz
{ N6=cqUM wt
$goods[$idx]['promote_price'] = ''; lSC3m=4g
} ca*USM
$goods[$idx]['id'] = $row['goods_id']; MI0'ou8l
$goods[$idx]['name'] = $row['goods_name']; EC&t+"=R
$goods[$idx]['brief'] = $row['goods_brief']; 2/sD#vC
$goods[$idx]['brand_name'] = $row['brand_name']; c!T^JZBb
$goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); IhwJYPLF
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; N5#qox$D
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']); L7_(KC h
$goods[$idx]['market_price'] = price_format($row['market_price']); F\Q)l+c
$goods[$idx]['shop_price'] = price_format($row['shop_price']); #`RYKQwB
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); ( t#w@<
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); cR}}N F
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); #HWz.Wb
} 0{F"b'h
return $goods; ~QFD ^SoK
} bYQ h{q
2.在需要调用商品的页面php文件(一般是index.php)里在 assign_dynamic('index'); 之前写上这段 (9*s:)zD-
$smarty->assign( 'ecshop_vc', get_keyword_goods('商城首页')); D%(9ot{!e
其中,商城首页是我在商品的“其他信息”-“商品关键词”一栏中填写的用于调用的关键词 `)\_
3. 在需要调用商品的dwt或lbi中用foreach就可以调啦 ;38W41d{
<!--{foreach from=$ecshop_vc item=goods}--> OMd{rH
<!--{/foreach}-->