1. 调用一级栏目
方法函数
<!--{foreach from=$categories item=cat}-->
<li><a href="{$cat.url}" target="_blank">{$cat.name|escape:html}</a></li>
<!--{/foreach}-->
1.5 栏目 单独调用一 二 级栏目
<!--{foreach from=$categories item=cat}-->
<div>
<h3><a href="{$cat.url}" target="_blank">{$cat.name|escape:html}</a></h3>
<p>
<!--{foreach from=$cat.cat_id item=child name='my_menu'}-->
<a href="{$childer.url}" target="_blank">{$childer.name|escape:html}</a> |
<!--{/foreach}-->
</p>
</div>
<!--{/foreach}-->
2. 调用多级栏目
<!--{foreach from=$categories item=cat}-->
<h2>
<a href="{$cat.url}">{$cat.name|escape:html}</a>
</h2>
<!--{foreach from=$cat.cat_id item=child name='my_menu'}-->
<!--{foreach from=$child.cat_id item=childer}-->
<li> <a href="{$childer.url}">{$childer.name|escape:html}</a></li>
<!--{/foreach}-->
<!--{/foreach}-->
<!--{/foreach}-->
- 商品调用
function get_my_goods($mark,$goods_type='',$limit='',$t=''){
$goods_type_tyid='';
if(!empty($t)){
$sql_ty = "select cat_id from ". $GLOBALS['ecs']->table('category')." where parent_id = $goods_type";
$type_arr = $GLOBALS['db']->getAll($sql_ty);
foreach ($type_arr AS $idx => $row){
$goods_type_tyid .= $row['cat_id'].',';
}
$goods_type = substr($goods_type_tyid,0,-1);
}
//取出所有符合条件的商品数据,并将结果存入对应的推荐类型数组中
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, RAND() AS rnd " .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' where 1=1 and is_on_sale=1 ";
if(!empty($mark)){
if($mark=='hot'){
$sql .= " and g.is_hot=1";
}else if($mark=='new'){
$sql .= " and g.is_new=1";
}else if($mark=='best'){
$sql .= " and g.is_best=1";
}
}
if(!empty($goods_type)){
$sql .= " and g.cat_id in ($goods_type) ";
}
$sql .= ' ORDER BY g.sort_order, g.last_update DESC';
if(!empty($limit)){
$sql .=" limit $limit";
}
echo $sql;
$result = $GLOBALS['db']->getAll($sql);
foreach ($result AS $idx => $row)
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
}
else
{
$goods[$idx]['promote_price'] = '';
}
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : '';
$goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']);
$goods[$idx]['market_price'] = price_format($row['market_price']);
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
}
return $goods;
}
使用方法:
$smarty->assign('ind_new_goods', get_my_goods('new','','0,12')); // 新品
$smarty->assign('ind_new_goods', get_my_goods('new','12','0,12')); //栏目ID为12的商品
$smarty->assign('ind_new_goods', get_my_goods('new','12','0,12',’a’)); // 调用栏目为12和上一级ID为12的商品
标签:
上一篇:
ecshop重写产品URL规则 下一篇:
ecshop修改商品数量后自动更新购物车功能