方法:在ECShop首页显示积分商城里的商品列表
需要修改两个文件:index.php、index.dwt
一、在 index.php 末尾添加一个 function:
/**
* 获得积分商城热门商品
*
* @param int $limit 列出条数
* @param int $ishot 是否只显示热销
* @return array
*/
function index_get_exchange($limit=3,$ishot=0){
/* 获得热门积分商品列表 */
$sql_ishot = $ishot ? " AND eg.is_hot=1 " : "";
$table_exchange_goods = $GLOBALS['ecs']->table('exchange_goods');
$table_goods = $GLOBALS['ecs']->table('goods');
$sql = "
SELECT
g.goods_id, g.goods_name, g.goods_name_style, eg.exchange_integral,
g.goods_type,g.goods_brief, g.goods_thumb, g.goods_img, eg.is_hot
FROM $table_exchange_goods AS eg
LEFT JOIN $table_goods AS g
ON g.goods_id = eg.goods_id
WHERE eg.is_exchange = 1 AND g.is_delete = 0 $sql_ishot
limit $limit
";
$res = $GLOBALS['db']->getAll($sql);
$arr = array();
foreach($res AS $idx => $row){
$arr[$idx]['name'] = $row['goods_name'];
$arr[$idx]['goods_brief'] = $row['goods_brief'];
$arr[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$arr[$idx]['exchange_integral'] = $row['exchange_integral'];
$arr[$idx]['type'] = $row['goods_type'];
$arr[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$idx]['url'] = build_uri('exchange_goods', array('gid'=>$row['goods_id']), $row['goods_name']);
}
return $arr;
}
二、index.dwt 中的调用代码:
<!--{if $exchange_goods}-->
<ul class="imgList">
<!--{foreach from=$exchange_goods item=goods}-->
<li>
<a href="{$goods.url}" class="thumb" title="{$goods.name|escape:html}"><img src="{$goods.thumb}" width="124" height="144" alt="{$goods.name|escape:html}" /></a>
<div class="title"><a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.name}</a></div>
<div class="price">
<div class="promote"><strong>{$lang.exchange_integral}</strong><span href="">{$goods.exchange_integral}</span></div>
</div>
</li>
<!--{/foreach}-->
</ul>
<!--{/if}-->
<完>