ectouch手机商城首页调用指定分类下的商品
日期:2018-08-15
ECTouch是国内市面上唯一开源的ECSHOP移动商城系统,为广大电商以最低的成本快速搭建移动商城。最近最一商城实例,手机版首页需要调用指定分类下的商品,ECtouch商城默认好像没有此调用方式,只能自己动手添加了,方法如下:
1、打开mobile\include\apps\default\model\IndexModel.class.php文件,在最下面 } 之前添加以下代码
2、打开mobile\include\apps\default\controller\IndexController.class.php文件
在 public function index()函数里面添加以下代码:
3、打开模板index.dwt,在合适位置添加调用代码:
上传了我自己修改好的文件供参考,或者可以直接覆盖(注意备份)
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, ' . "NULLp.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_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_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值
上传了我自己修改好的文件供参考,或者可以直接覆盖(注意备份)
本文原创地址:https://www.ecshopok.com/article-435.html
版权所有 © 转载时必须以链接形式注明出处!
觉得本文对您有用,想收藏下来!方法很简单:请点击-〉
我们一直坚持白天工作、晚上熬夜更新资源,付出了巨大的精力和时间,其中的辛酸难以言述。
暂无评论,来发表一个吧