ectouch手機商城首頁調用指定分類下的商品

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_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值


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章