,首页增进最新上架商品

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

,首页增进最新上架商品
includes\lib_goods.php
最后头增进一个函数
/**
* 最新上架商品
*
* @accesspublic
* @returnarray
*/
dingjian121.com
baijle1663.com
baiwei595.com

function get_update_goods($num = '0')
{
$sql="SELECT goods_id, goods_name, goods_name_style, goods_thumb, shop_price, market_price, promote_price " .
'FROM ' . $GLOBALS['ecs']->table('goods')." where is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 order by goods_id desc limit $num";
$goods = $GLOBALS['db']->getAll($sql);
for ($i = 0, $count = count($goods); $i < $count; $i++)
{
//处理赏罚促销价值
if ($goods[$i]['promote_price'] > 0)
{
$goods[$i]['promote_price'] = price_format($goods[$i]['promote_price']);;
}
else
{
$goods[$i]['promote_price'] = '';
}

$goods[$i]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($goods[$i]['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $goods[$i]['goods_name'];
$goods[$i]['url']= build_uri('goods', array('gid' => $goods[$i]['goods_id']), $goods[$i]['goods_name']);
$goods[$i]['short_style_name'] = add_style($goods[$i]['short_name'], $goods[$i]['goods_name_style']);
$goods[$i]['thumb'] = get_image_path($goods[$i]['goods_id'], $goods[$i]['goods_thumb'],true);
$goods[$i]['shop_price'] = price_format($goods[$i]['shop_price']);
$goods[$i]['market_price'] = price_format($goods[$i]['market_price']);
}
return $goods;
}

index.php 里增进一个
$smarty->assign('update_goods',get_update_goods());

最后模板文件夹library下新建一个 update_goods.lbi -> (10) 代表商品数目
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="box">
<div class="box_2 centerPadd">
<div class="itemTit" id="itemBest">
<h2>最新上架</h2>
</div>
<div class="clearfix goodsBox">
<!–{foreach from=get_update_goods(10) item=goods}–>
<div class="goodsItem">
<span class="best"></span>
<a href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="goodsimg" /></a><br />
<p><a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.short_style_name}</a></p>
<font class="f1">
<!– {if $goods.promote_price neq ""} –>
促销价:{$goods.promote_price}<br />
本店价:{$goods.shop_price}<br />
<!– {else}–>
本店价:{$goods.shop_price}<br />
市场价:{$goods.market_price}<br />
<!–{/if}–>
</font>
</div>
<!– { /foreach }–>
<div class="more"><a href="../search.php?intro=news"><img src="images/more.gif" /></a></div>
</div>
</div>
</div>
<div class="blank5"></div>