ecshop mobile首页循环显示分类及分类下商品

2016-09-23 浏览:1718
ecshop mobile首页循环显示分类及分类下商品
评论:(0)复制地址

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}  &nbsp;&nbsp;总销量:{$goods.sales_volume_base}</div>

</div>

</a>

</div>

</li>

                    {/foreach}

</ul>

</div>

</div>

            {/foreach}


评论:(0)复制地址
发布:苗景云 | 分类:管理&经济 | Tags:ECshop mobile

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。