1、打开mobile/index.php,添加以下代码
//获取商品分类
$pcat_array = get_categories_tree();
foreach ($pcat_array as $key => $pcat_data)
{
$pcat_array[$key]['goods_list'] = get_parent_category_goods($pcat_data['id']);
$pcat_array[$key]['name'] = encode_output($pcat_data['name']);
}
$smarty->assign('pcat_array' , $pcat_array);
//获取分类下商品
function get_parent_category_goods($cat_id){
global $db;
global $ecs;
$children = get_children($cat_id);
$arr = array();
$where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".
"g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')';
/* 获得商品列表 */
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_brief, g.goods_thumb , g.goods_img, shop_price,sales_volume_base ' .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . " WHERE $where order by g.sort_order desc ";
$res = $GLOBALS['db']->selectLimit($sql, 50, 0); //50为调用数量
while ($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$row['goods_id']]['id'] = $row['goods_id'];
$arr[$row['goods_id']]['name'] = $row['goods_name'];
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['thumb'] = empty($row['goods_thumb']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_thumb'];
$arr[$row['goods_id']]['goods_img'] = empty($row['goods_img']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_img'];
$arr[$row['goods_id']]['sales_volume_base'] = $row['sales_volume_base'];
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
}
return $arr;
}
2、index.dwt中使用以下代码
{foreach from=$pcat_array item=pcat_data}
<div class="row row_list">
<div class="list-title"> <h2>{$pcat_data.name}</h2> <a href="category.php?c_id={$pcat_data.id}">更多<i class="if if-chevron-right"></i></a> </div>
<div id="list">
<ul>
{foreach from=$pcat_data.goods_list item=goods}
<li>
<div class="type_ad">
<a href="goods.php?id={$goods.id}">
<div class="imgurl">
<img src="./../{$goods.thumb}">
</div>
<div class="info">
<div class="product_name">
<span class="name">{$goods.name}</span>
</div>
<div class="price">价格:{$goods.shop_price} 总销量:{$goods.sales_volume_base}</div>
</div>
</a>
</div>
</li>
{/foreach}
</ul>
</div>
</div>
{/foreach}
相关文章
ecshop出现Warning: Invalid argument supplied for foreach()错误2019-02-26
Ecshop 分类页产品列表不同分类调用不同产品属性2018-03-08
ECSHOP商品属性调用到任意页面方法2018-03-01
ECSHOP商品列表页显示每个商品的品牌2018-02-28
Ecshop 分类页品牌调用商品数量2018-02-28
ecshop调整默认商品图片排序2018-02-27
ecshop各个页面调用商品销售量方法2016-09-23
ecshop后台添加虚拟销量以及前台显示销量2016-09-22
ecshop重新导入数据库,管理员和密码正确登录失败2016-09-21
ecshop 共享首页推荐商品调用商品品牌方法2015-08-06