ECTouch是国内市面上唯一开源的ECSHOP移动商城系统,为广大电商以最低的成本快速搭建移动商城。最近最一商城实例,手机版首页需要调用指定分类下的商品,ECtouch商城默认好像没有此调用方式,只能自己动手添加了。

方法如下:

1、打开mobile\include\apps\default\model\IndexModel.class.php

在最下面}之前添加以下代码

/***获得指定分类下的商品*/functionassign_cat_goods($cat_id){$children=get_children($cat_id);$sql='SELECTg.goods_id,g.goods_name,g.market_price,g.shop_priceASorg_price,'."IFNULL(mp.user_price,g.shop_price*'$_SESSION[discount]')ASshop_price,".'g.promote_price,promote_start_date,promote_end_date,g.goods_brief,g.goods_thumb,g.goods_img'."FROM".$this->pre.'goodsASg'."LEFTJOIN".$this->pre."member_priceASmp"."ONmp.goods_id=g.goods_idANDmp.user_rank='$_SESSION[user_rank]'".'WHEREg.is_on_sale=1ANDg.is_alone_sale=1AND'.'g.is_delete=0AND('.$children.'OR'.model('Goods')->get_extension_goods($children).')';$sql.='ORDERBYg.sort_order,g.goods_idDESC';$sql.='LIMIT3';$res=$this->query($sql);$goods=array();foreach($resAS$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]['market_price']=price_format($row['market_price']);$goods[$idx]['short_name']=C('goods_name_length')>0?sub_str($row['goods_name'],C('goods_name_length')):$row['goods_name'];$goods[$idx]['shop_price']=price_format($row['shop_price']);$goods[$idx]['thumb']=get_p_w_picpath_path($row['goods_id'],$row['goods_thumb'],true);$goods[$idx]['goods_img']=get_p_w_picpath_path($row['goods_id'],$row['goods_img']);$goods[$idx]['url']=build_uri('goods/index',array('id'=>$row['goods_id']));}ECTouch::view()->assign('cat_goods_'.$cat_id,$goods);return$goods;}

其中:

$sql.='LIMIT3';

数字 3 代表的是调用3个商品,可自己修改

2、打开:mobile\include\apps\default\controller\IndexController.class.php

在public function index()函数里面添加以下代码:

//首页指定分类下的商品$this->assign('cat_id1',model('Index')->assign_cat_goods(1));$this->assign('cat_id5',model('Index')->assign_cat_goods(5));

代码中的数字1和5 代表 分类ID1和分类ID5

可自己修改或新增

3、打开模板index.dwt,在合适位置添加调用代码:

{foreachfrom=$cat_id5item=goodsname=cat_id5}<li><ahref="{$goods.url}"title="{$goods.name|escape:html}"><divclass="products_kuang"><imgsrc="{$option.static_path}{$goods.thumb}"></div><divclass="goods_name">{$goods.name}</div><spanclass="price">{if$goods.promote_price}{$goods.promote_price}{else}{$goods.shop_price}{/if}</span></a></li>{/foreach}

from=$cat_id5

自己修改from值