当前位置:Gxlcms > PHP教程 > 基于ecshop的移动端etouch实现动态获取分类商品列表

基于ecshop的移动端etouch实现动态获取分类商品列表

时间:2021-07-01 10:21:17 帮助过:12人阅读

修改文件 category.php

关键两个地方需要修改

if ($_GET['acthttps://www.gxlcms.com/'] == 'asynclisthttps://www.gxlcms.com/') {
        $sayList = array();
        if (is_array($goodslist)) {
            foreach ($goodslist as $vo) {
                $shop_price = empty($vo['promote_pricehttps://www.gxlcms.com/']) ? $vo['shop_pricehttps://www.gxlcms.com/']:$vo['promote_pricehttps://www.gxlcms.com/'];
                $watermark_img = empty($vo['watermark_imghttps://www.gxlcms.com/']) ? 'https://www.gxlcms.com/':'基于ecshop的移动端 etouch实现动态获取分类商品列表.$vo['goods_namehttps://www.gxlcms.com/'].'" />https://www.gxlcms.com/';
               /* $sayList[] = array(
                    'pro-innerhttps://www.gxlcms.com/' => '
         .$vo['urlhttps://www.gxlcms.com/'].'" > 基于ecshop的移动端 etouch实现动态获取分类商品列表.$vo['goods_namehttps://www.gxlcms.com/'].'">  
        
           .$vo['urlhttps://www.gxlcms.com/'].'" >https://www.gxlcms.com/'.$vo['namehttps://www.gxlcms.com/'].' 
          
          
            https://www.gxlcms.com/'. $shop_price .' 
          
           https://www.gxlcms.com/'.$vo['market_pricehttps://www.gxlcms.com/'].'
          月销:https://www.gxlcms.com/'.$vo['sales_counthttps://www.gxlcms.com/'].'
          https://www.gxlcms.com/'.$watermark_img.'
        https://www.gxlcms.com/'
                );*/
                $collectStr = 'https://www.gxlcms.com/';
                if($vo['collecthttps://www.gxlcms.com/']){
                    //如果已经搜藏了那么
                    $collectStr = '$vo['goods_idhttps://www.gxlcms.com/'].')">https://www.gxlcms.com/';
                }else{
                    //如果没有搜藏那么
                    $collectStr = '$vo['goods_idhttps://www.gxlcms.com/'].')">https://www.gxlcms.com/';
                }
                $sayList[] = array(
                 'pro-innerhttps://www.gxlcms.com/'=>'
                     .$vo['urlhttps://www.gxlcms.com/'].'">
                        基于ecshop的移动端 etouch实现动态获取分类商品列表.$vo['goods_namehttps://www.gxlcms.com/'].'">
                    
                    
                        
                            https://www.gxlcms.com/'.$vo['namehttps://www.gxlcms.com/'].'
                        
                        

https://www.gxlcms.com/'. $shop_price .https://www.gxlcms.com/'

月销:https://www.gxlcms.com/'.$vo['sales_counthttps://www.gxlcms.com/'].'

https://www.gxlcms.com/'
.$collectStr.' https://www.gxlcms.com/' ); } } echo json_encode($sayList); exit; }

还有一个叫做 category_get_goods 这个函数此函数新增了一个字段 collect返回字段可以用于前端页面视图渲染的时候实现判断是否已经搜藏 并且根据是否搜藏显示不同的样式和绑定不同的事件函数

/**
 * 获得分类下的商品
 *
 * @access  public
 * @param   string  $children
 * @return  array
 */functioncategory_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order)
{$display = $GLOBALS['displayhttps://www.gxlcms.com/'];
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".
            "g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')https://www.gxlcms.com/';

    if ($brand > 0)
    {
        $where .=  "AND g.brand_id=$brand ";
    }

    if ($min > 0)
    {
        $where .= " AND g.shop_price >= $min ";
    }

    if ($max > 0)
    {
        $where .= " AND g.shop_price <= $max ";
    }

    /* 获得商品列表 */$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, https://www.gxlcms.com/' .
                "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
                'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img https://www.gxlcms.com/' .
            'FROM https://www.gxlcms.com/' . $GLOBALS['ecshttps://www.gxlcms.com/']->table('goodshttps://www.gxlcms.com/') . ' AS g https://www.gxlcms.com/' .
            'LEFT JOIN https://www.gxlcms.com/' . $GLOBALS['ecshttps://www.gxlcms.com/']->table('member_pricehttps://www.gxlcms.com/') . ' AS mp https://www.gxlcms.com/' .
                "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
            "WHERE $where $ext ORDER BY $sort $order";
    $res = $GLOBALS['dbhttps://www.gxlcms.com/']->selectLimit($sql, $size, ($page - 1) * $size);

    $arr = array();
    while ($row = $GLOBALS['dbhttps://www.gxlcms.com/']->fetchRow($res))
    {
        if ($row['promote_pricehttps://www.gxlcms.com/'] > 0)
        {
            $promote_price = bargain_price($row['promote_pricehttps://www.gxlcms.com/'], $row['promote_start_datehttps://www.gxlcms.com/'], $row['promote_end_datehttps://www.gxlcms.com/']);
        }
        else
        {
            $promote_price = 0;
        }

        /* 处理商品水印图片 */$watermark_img = 'https://www.gxlcms.com/';

        if ($promote_price != 0)
        {
            $watermark_img = "watermark_promote_small";
        }
        elseif ($row['is_newhttps://www.gxlcms.com/'] != 0)
        {
            $watermark_img = "watermark_new_small";
        }
        elseif ($row['is_besthttps://www.gxlcms.com/'] != 0)
        {
            $watermark_img = "watermark_best_small";
        }
        elseif ($row['is_hothttps://www.gxlcms.com/'] != 0)
        {
            $watermark_img = 'watermark_hot_smallhttps://www.gxlcms.com/';
        }

        if ($watermark_img != 'https://www.gxlcms.com/')
        {
            $arr[$row['goods_idhttps://www.gxlcms.com/']]['watermark_imghttps://www.gxlcms.com/'] =  $watermark_img;
        }

        $arr[$row['goods_idhttps://www.gxlcms.com/']]['goods_idhttps://www.gxlcms.com/']         = $row['goods_idhttps://www.gxlcms.com/'];
        if($display == 'gridhttps://www.gxlcms.com/')
        {
            $arr[$row['goods_idhttps://www.gxlcms.com/']]['goods_namehttps://www.gxlcms.com/']       = $GLOBALS['_CFGhttps://www.gxlcms.com/']['goods_name_lengthhttps://www.gxlcms.com/'] > 0 ? sub_str($row['goods_namehttps://www.gxlcms.com/'], $GLOBALS['_CFGhttps://www.gxlcms.com/']['goods_name_lengthhttps://www.gxlcms.com/']) : $row['goods_namehttps://www.gxlcms.com/'];
        }
        else
        {
            $arr[$row['goods_idhttps://www.gxlcms.com/']]['goods_namehttps://www.gxlcms.com/']       = $row['goods_namehttps://www.gxlcms.com/'];
        }
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['namehttps://www.gxlcms.com/']             = $row['goods_namehttps://www.gxlcms.com/'];
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['goods_briefhttps://www.gxlcms.com/']      = $row['goods_briefhttps://www.gxlcms.com/'];
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['goods_style_namehttps://www.gxlcms.com/'] = add_style($row['goods_namehttps://www.gxlcms.com/'],$row['goods_name_stylehttps://www.gxlcms.com/']);
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['market_pricehttps://www.gxlcms.com/']     = price_format($row['market_pricehttps://www.gxlcms.com/']);
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['shop_pricehttps://www.gxlcms.com/']       = price_format($row['shop_pricehttps://www.gxlcms.com/']);
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['typehttps://www.gxlcms.com/']             = $row['goods_typehttps://www.gxlcms.com/'];
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['promote_pricehttps://www.gxlcms.com/']    = ($promote_price > 0) ? price_format($promote_price) : 'https://www.gxlcms.com/';
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['goods_thumbhttps://www.gxlcms.com/']      = get_image_path($row['goods_idhttps://www.gxlcms.com/'], $row['goods_thumbhttps://www.gxlcms.com/'], true);
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['goods_imghttps://www.gxlcms.com/']        = get_image_path($row['goods_idhttps://www.gxlcms.com/'], $row['goods_imghttps://www.gxlcms.com/']);
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['urlhttps://www.gxlcms.com/']              = build_uri('goodshttps://www.gxlcms.com/', array('gidhttps://www.gxlcms.com/'=>$row['goods_idhttps://www.gxlcms.com/']), $row['goods_namehttps://www.gxlcms.com/']);
        $arr[$row['goods_idhttps://www.gxlcms.com/']]['sales_counthttps://www.gxlcms.com/']      = get_sales_volume($row['goods_idhttps://www.gxlcms.com/']); //显示月销量 by wangif (isset($_SESSION['user_idhttps://www.gxlcms.com/']) || $_SESSION['user_idhttps://www.gxlcms.com/'] != 0)
        { 
            /* 检查是否已经存在于用户的收藏夹 */$sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecshttps://www.gxlcms.com/']->table('collect_goodshttps://www.gxlcms.com/') .
                " WHERE user_id='$_SESSION[user_id]' AND goods_id = '".$row['goods_idhttps://www.gxlcms.com/']."'";

            if ($GLOBALS['dbhttps://www.gxlcms.com/']->GetOne($sql) > 0)
            {

                $arr[$row['goods_idhttps://www.gxlcms.com/']]['collecthttps://www.gxlcms.com/'] = 1;
            }
            else
            {
                $arr[$row['goods_idhttps://www.gxlcms.com/']]['collecthttps://www.gxlcms.com/'] = 0;
            }

        }else{
            $arr[$row['goods_idhttps://www.gxlcms.com/']]['collecthttps://www.gxlcms.com/'] = 0;
        }


    }

    return$arr;
}

客户端js代码参考

/* *

 * 添加商品到收藏夹

 */var _current_collect = null;
var _current_goodsId = 0;

functioncollect(_this,goodsId)
{
  _current_collect = _this;
  _current_goodsId = goodsId;
  jQuery.get('user.php?act=collecthttps://www.gxlcms.com/',{id:goodsId},collectResponse,"JSON");
}

functionuncollect(_this,goodsId)
{
  _current_collect = _this;
  _current_goodsId = goodsId;
  jQuery.get('user.php?act=uncollecthttps://www.gxlcms.com/',{id:goodsId},collectResponse,"JSON");
}


/* *

 * 处理收藏商品的反馈信息

 */functioncollectResponse(result)
{if(parseInt(result.error) === 0){
         _current_collect.className = 'https://www.gxlcms.com/';
         _current_collect.className ="ycd-font-icon uncollect";
         _current_collect.setAttribute('onclickhttps://www.gxlcms.com/',"uncollect(this,"+_current_goodsId+")");
         _current_collect.innerHTML = 'https://www.gxlcms.com/';
     }
     if(parseInt(result.error) === 3){

         _current_collect.className = 'https://www.gxlcms.com/';
         _current_collect.className ="ycd-font-icon collect";
         _current_collect.setAttribute('onclickhttps://www.gxlcms.com/',"collect(this,"+_current_goodsId+")");
         _current_collect.innerHTML = 'https://www.gxlcms.com/';
     }
    //这里加入成功//注意这里引入了一个自己写的基于zepto移动端函数库的一个插件 请参考我以前写的一篇文章里面有这个插件的代码
    Zepto('bodyhttps://www.gxlcms.com/').popup({
            title:'提示信息https://www.gxlcms.com/'
            ,id:'alerthttps://www.gxlcms.com/'
            ,closeOnOk:true
            ,ok:'确定https://www.gxlcms.com/',
            message:result.message
        }); 

}

总结

以前非常喜欢php 弄过一段时间 所以php代码也是基本上都能够看懂 mysql 也学过
没有php 基础的童鞋可以先去学学php基础
现在博主努力专研前端 后端也在学习 最近学习javascript 和 html5的新api 这些
记录下自己的工作

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了基于ecshop的移动端 etouch实现动态获取分类商品列表,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

  • 人气教程排行