ecshop的wap中商品显示处理

2010-11-22 23:42 来源:www.chinab4c.com 作者:admin

    ecshop的wap中。首页中。商品显示和商品分类都十分的混乱。不适合ecshop用户体验.我们现在结合mobile下的index.php.来讲述如何在ecshop的wap的首页,进行ecshop二次开发,让分类显示中.显示大分类下的若干商品。不至于让ecshop显示的很空洞.

 1: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']);
    if ($pcat_data['cat_id'])
    {
        if (count($pcat_data['cat_id']) > 3)
        {
            $pcat_array[$key]['cat_id'] = array_slice($pcat_data['cat_id'], 0, 3);
        }
        foreach ($pcat_array[$key]['cat_id'] as $k => $v)
        {
            $pcat_array[$key]['cat_id'][$k]['name'] = encode_output($v['name']);
        }
    }
}

  在ecshop的首页代码中增加以下函数。

  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 ' .
            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g '  . " WHERE $where  order by g.sort_order desc ";
     $res = $GLOBALS['db']->selectLimit($sql, 5, 0);
  while ($row = $GLOBALS['db']->fetchRow($res))
    {
     

        $arr[$row['goods_id']]['goods_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']]['url']              = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
    }

    return $arr;
}

 

 2:index.htm中修改以下

 {foreach from=$pcat_array item=pcat_data}
【<a href='category.php?c_id={$pcat_data.id}'>{$pcat_data.name}</a>|
{foreach from=$pcat_data['cat_id'] item=cat_data name=foo}
{if $smarty.foreach.foo.iteration <= 3}
<a href='category.php?c_id={$cat_data.id}'>{$cat_data.name}</a>
{/if}
{if $smarty.foreach.foo.last}<a href='cat_all.php'>更多</a>】<br/>{/if}

{/foreach}

{foreach from = $pcat_data.goods_list item = item_list}
<a href="{$item_list.url}">{$item_list.name}</a><br>
{/foreach}

 

<br/>


{/foreach}
 

    这样就完成了ecshop的wap首页分类中。列表出该分类下的若干商品.

 来源:http://www.chinab4c.com