ECTouch是国内市面上唯一开源的ECSHOP移动商城系统,为广大电商以最低的成本快速搭建移动商城。最近最一商城实例,手机版首页需要调用指定分类下的商品,ECtouch商城默认好像没有此调用方式,只能自己动手添加了。
方法如下:
1、打开mobile\include\apps\default\model\IndexModel.class.php
在最下面 } 之前添加以下代码
/** * 获得指定分类下的商品 */ function assign_cat_goods($cat_id) { $children = get_children($cat_id); $sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, " . 'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' . "FROM " . $this->pre . 'goods AS g ' . "LEFT JOIN " . $this->pre . "member_price AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " . 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ' . 'g.is_delete = 0 AND (' . $children . 'OR ' . model('Goods')->get_extension_goods($children) . ') '; $sql .= 'ORDER BY g.sort_order, g.goods_id DESC'; $sql .= ' LIMIT 3'; $res = $this->query($sql); $goods = array(); foreach ($res 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]['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 .= ' LIMIT 3';
数字 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,在合适位置添加调用代码:
{foreach from=$cat_id5 item=goods name=cat_id5} <li> <a href="{$goods.url}" title="{$goods.name|escape:html}"> <div class="products_kuang"> <img src="{$option.static_path}{$goods.thumb}"> </div> <div class="goods_name"> {$goods.name} </div> <span class="price">{if $goods.promote_price}{$goods.promote_price}{else}{$goods.shop_price}{/if}</span> </a> </li> {/foreach}
from=$cat_id5
自己修改from值
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。