ホームページ  >  記事  >  バックエンド開発  >  ecshopベースのモバイルetouchは、分類された商品リストの動的な取得を実装します

ecshopベースのモバイルetouchは、分類された商品リストの動的な取得を実装します

WBOY
WBOYオリジナル
2016-07-29 08:57:051547ブラウズ

ファイル category.php を変更します

2 つの重要な場所を変更する必要があります

<code><span>if</span> (<span>$_GET</span>[<span>'act'</span>] == <span>'asynclist'</span>) {
        <span>$sayList</span> = array();
        <span>if</span> (is_array(<span>$goodslist</span>)) {
            foreach (<span>$goodslist</span> as <span>$vo</span>) {
                <span>$shop_price</span> = empty(<span>$vo</span>[<span>'promote_price'</span>]) ? <span>$vo</span>[<span>'shop_price'</span>]:<span>$vo</span>[<span>'promote_price'</span>];
                <span>$watermark_img</span> = empty(<span>$vo</span>[<span>'watermark_img'</span>]) ? <span>''</span>:<span>'<img width="55" height="16" src="'</span>.<span>'themes/'</span> . <span>$_CFG</span>[<span>'template'</span>].<span>'/images/'</span>.<span>$vo</span>[<span>'watermark_img'</span>].<span>'.png" alt="基于ecshop的移动端 etouch实现动态获取分类商品列表"</span>.<span>$vo</span>[<span>'goods_name'</span>].<span>'" />'</span>;
               /* <span>$sayList</span>[] = array(
                    <span>'pro-inner'</span> => <span>'
        <div> <a href="'</span>.<span>$vo</span>[<span>'url'</span>].<span>'" > <img src="'</span>.<span>$config</span>[<span>'site_url'</span>].<span>$vo</span>[<span>'goods_thumb'</span>].<span>'" alt="基于ecshop的移动端 etouch实现动态获取分类商品列表"</span>.<span>$vo</span>[<span>'goods_name'</span>].<span>'"> </a> </div>
        <div>
          <div> <a href="'</span>.<span>$vo</span>[<span>'url'</span>].<span>'" >'</span>.<span>$vo</span>[<span>'name'</span>].<span>'</a> </div>
          <div></div>
          <div>
            <em>'</span>. <span>$shop_price</span> .<span>'</em> 
          </div>
          <div> <del>'</span>.<span>$vo</span>[<span>'market_price'</span>].<span>'</del></div>
          <div>月销:<em>'</span>.<span>$vo</span>[<span>'sales_count'</span>].<span>'</em></div>
          <div>'</span>.<span>$watermark_img</span>.<span>'</div>
        </div>'</span>
                );*/
                <span>$collectStr</span> = <span>''</span>;
                <span>if</span>(<span>$vo</span>[<span>'collect'</span>]){
                    //如果已经搜藏了那么
                    <span>$collectStr</span> = <span>'<a >$vo</span>[<span>'goods_id'</span>].<span>')">&#xe63e;</a>'</span>;
                }<span>else</span>{
                    //如果没有搜藏那么
                    <span>$collectStr</span> = <span>'<a >$vo</span>[<span>'goods_id'</span>].<span>')">&#xe620;</a>'</span>;
                }
                <span>$sayList</span>[] = array(
                 <span>'pro-inner'</span>=><span>'
                     <a href="'</span>.<span>$vo</span>[<span>'url'</span>].<span>'">
                        <img src="'</span>.<span>$config</span>[<span>'site_url'</span>].<span>$vo</span>[<span>'goods_thumb'</span>].<span>'" alt="基于ecshop的移动端 etouch实现动态获取分类商品列表"</span>.<span>$vo</span>[<span>'goods_name'</span>].<span>'">
                    </a>
                    <div>
                        <span>
                            '</span>.<span>$vo</span>[<span>'name'</span>].<span>'
                        </span>
                        <p>
                            <span>'</span>. <span>$shop_price</span> .<span>'</span>
                        </p>
                        <p>
                            月销:'</span>.<span>$vo</span>[<span>'sales_count'</span>].<span>'
                        </p>
                    </div>
                    '</span>.<span>$collectStr</span>.<span>'
                    <div>
                         <!--<span  data-operation="pre" data-goods-id="'</span>.<span>$vo</span>[<span>'goods_id'</span>].<span>'">&#xe62a;</span>-->
                         <input type="number"  name="number" value="1" min="1" max="1" />
                         <span  data-operation="next" data-goods-id="'</span>.<span>$vo</span>[<span>'goods_id'</span>].<span>'">&#xe62d;</span>
                    </div>
                 '</span>
                );
            }
        }
        <span>echo</span> json_encode(<span>$sayList</span>);
        <span>exit</span>;
    }</code>

category_get_goods という関数もあります。この関数は、レンダリング時に収集されたかどうかを判断するために使用できる新しいフィールドを追加します。フロントエンドページビューは、収集されるかどうかに応じて、異なるスタイルが表示され、異なるイベント関数がバインドされます

<code><span>/**
 * 获得分类下的商品
 *
 *<span> @access</span>  public
 *<span> @param</span>   string  $children
 *<span> @return</span>  array
 */</span><span><span>function</span><span>category_get_goods</span><span>(<span>$children</span>, <span>$brand</span>, <span>$min</span>, <span>$max</span>, <span>$ext</span>, <span>$size</span>, <span>$page</span>, <span>$sort</span>, <span>$order</span>)</span>
{</span><span>$display</span> = <span>$GLOBALS</span>[<span>'display'</span>];
    <span>$where</span> = <span>"g.is_on_sale = 1 AND g.is_alone_sale = 1 AND "</span>.
            <span>"g.is_delete = 0 AND ($children OR "</span> . get_extension_goods(<span>$children</span>) . <span>')'</span>;

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

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

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

    <span>/* 获得商品列表 */</span><span>$sql</span> = <span>'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, '</span> .
                <span>"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, "</span> .
                <span>'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img '</span> .
            <span>'FROM '</span> . <span>$GLOBALS</span>[<span>'ecs'</span>]->table(<span>'goods'</span>) . <span>' AS g '</span> .
            <span>'LEFT JOIN '</span> . <span>$GLOBALS</span>[<span>'ecs'</span>]->table(<span>'member_price'</span>) . <span>' AS mp '</span> .
                <span>"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' "</span> .
            <span>"WHERE $where $ext ORDER BY $sort $order"</span>;
    <span>$res</span> = <span>$GLOBALS</span>[<span>'db'</span>]->selectLimit(<span>$sql</span>, <span>$size</span>, (<span>$page</span> - <span>1</span>) * <span>$size</span>);

    <span>$arr</span> = <span>array</span>();
    <span>while</span> (<span>$row</span> = <span>$GLOBALS</span>[<span>'db'</span>]->fetchRow(<span>$res</span>))
    {
        <span>if</span> (<span>$row</span>[<span>'promote_price'</span>] > <span>0</span>)
        {
            <span>$promote_price</span> = bargain_price(<span>$row</span>[<span>'promote_price'</span>], <span>$row</span>[<span>'promote_start_date'</span>], <span>$row</span>[<span>'promote_end_date'</span>]);
        }
        <span>else</span>
        {
            <span>$promote_price</span> = <span>0</span>;
        }

        <span>/* 处理商品水印图片 */</span><span>$watermark_img</span> = <span>''</span>;

        <span>if</span> (<span>$promote_price</span> != <span>0</span>)
        {
            <span>$watermark_img</span> = <span>"watermark_promote_small"</span>;
        }
        <span>elseif</span> (<span>$row</span>[<span>'is_new'</span>] != <span>0</span>)
        {
            <span>$watermark_img</span> = <span>"watermark_new_small"</span>;
        }
        <span>elseif</span> (<span>$row</span>[<span>'is_best'</span>] != <span>0</span>)
        {
            <span>$watermark_img</span> = <span>"watermark_best_small"</span>;
        }
        <span>elseif</span> (<span>$row</span>[<span>'is_hot'</span>] != <span>0</span>)
        {
            <span>$watermark_img</span> = <span>'watermark_hot_small'</span>;
        }

        <span>if</span> (<span>$watermark_img</span> != <span>''</span>)
        {
            <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'watermark_img'</span>] =  <span>$watermark_img</span>;
        }

        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'goods_id'</span>]         = <span>$row</span>[<span>'goods_id'</span>];
        <span>if</span>(<span>$display</span> == <span>'grid'</span>)
        {
            <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'goods_name'</span>]       = <span>$GLOBALS</span>[<span>'_CFG'</span>][<span>'goods_name_length'</span>] > <span>0</span> ? sub_str(<span>$row</span>[<span>'goods_name'</span>], <span>$GLOBALS</span>[<span>'_CFG'</span>][<span>'goods_name_length'</span>]) : <span>$row</span>[<span>'goods_name'</span>];
        }
        <span>else</span>
        {
            <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'goods_name'</span>]       = <span>$row</span>[<span>'goods_name'</span>];
        }
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'name'</span>]             = <span>$row</span>[<span>'goods_name'</span>];
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'goods_brief'</span>]      = <span>$row</span>[<span>'goods_brief'</span>];
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'goods_style_name'</span>] = add_style(<span>$row</span>[<span>'goods_name'</span>],<span>$row</span>[<span>'goods_name_style'</span>]);
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'market_price'</span>]     = price_format(<span>$row</span>[<span>'market_price'</span>]);
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'shop_price'</span>]       = price_format(<span>$row</span>[<span>'shop_price'</span>]);
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'type'</span>]             = <span>$row</span>[<span>'goods_type'</span>];
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'promote_price'</span>]    = (<span>$promote_price</span> > <span>0</span>) ? price_format(<span>$promote_price</span>) : <span>''</span>;
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'goods_thumb'</span>]      = get_image_path(<span>$row</span>[<span>'goods_id'</span>], <span>$row</span>[<span>'goods_thumb'</span>], <span>true</span>);
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'goods_img'</span>]        = get_image_path(<span>$row</span>[<span>'goods_id'</span>], <span>$row</span>[<span>'goods_img'</span>]);
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'url'</span>]              = build_uri(<span>'goods'</span>, <span>array</span>(<span>'gid'</span>=><span>$row</span>[<span>'goods_id'</span>]), <span>$row</span>[<span>'goods_name'</span>]);
        <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'sales_count'</span>]      = get_sales_volume(<span>$row</span>[<span>'goods_id'</span>]); <span>//显示月销量 by wang</span><span>if</span> (<span>isset</span>(<span>$_SESSION</span>[<span>'user_id'</span>]) || <span>$_SESSION</span>[<span>'user_id'</span>] != <span>0</span>)
        { 
            <span>/* 检查是否已经存在于用户的收藏夹 */</span><span>$sql</span> = <span>"SELECT COUNT(*) FROM "</span> .<span>$GLOBALS</span>[<span>'ecs'</span>]->table(<span>'collect_goods'</span>) .
                <span>" WHERE user_id='$_SESSION[user_id]' AND goods_id = '"</span>.<span>$row</span>[<span>'goods_id'</span>].<span>"'"</span>;

            <span>if</span> (<span>$GLOBALS</span>[<span>'db'</span>]->GetOne(<span>$sql</span>) > <span>0</span>)
            {

                <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'collect'</span>] = <span>1</span>;
            }
            <span>else</span>
            {
                <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'collect'</span>] = <span>0</span>;
            }

        }<span>else</span>{
            <span>$arr</span>[<span>$row</span>[<span>'goods_id'</span>]][<span>'collect'</span>] = <span>0</span>;
        }


    }

    <span>return</span><span>$arr</span>;
}</span></code>

クライアントjsコードリファレンス

<code><span>/* *

 * 添加商品到收藏夹

 */</span><span>var</span> _current_collect = <span>null</span>;
<span>var</span> _current_goodsId = <span>0</span>;

<span><span>function</span><span>collect</span><span>(_this,goodsId)</span>
{</span>
  _current_collect = _this;
  _current_goodsId = goodsId;
  jQuery.get(<span>'user.php?act=collect'</span>,{id:goodsId},collectResponse,<span>"JSON"</span>);
}

<span><span>function</span><span>uncollect</span><span>(_this,goodsId)</span>
{</span>
  _current_collect = _this;
  _current_goodsId = goodsId;
  jQuery.get(<span>'user.php?act=uncollect'</span>,{id:goodsId},collectResponse,<span>"JSON"</span>);
}


<span>/* *

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

 */</span><span><span>function</span><span>collectResponse</span><span>(result)</span>
{</span><span>if</span>(<span>parseInt</span>(result.error) === <span>0</span>){
         _current_collect.className = <span>''</span>;
         _current_collect.className =<span>"ycd-font-icon uncollect"</span>;
         _current_collect.setAttribute(<span>'onclick'</span>,<span>"uncollect(this,"</span>+_current_goodsId+<span>")"</span>);
         _current_collect.innerHTML = <span>'&#xe63e;'</span>;
     }
     <span>if</span>(<span>parseInt</span>(result.error) === <span>3</span>){

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

}</code>

概要

私はphpがとても好きでした。しばらく勉強したので、php コードでの mysql も基本的に理解できるようになりました
PHP の基礎を持たない子供用シューズは、最初に PHP の基礎を学ぶことができます
現在、ブロガーはフロントエンドとバックエンドに特化して頑張っています。最近、JavaScript と HTML5 の新しい API を学びました。 作業を記録します

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); }); 上記は、コンテンツの側面を含め、分類された製品のリストを動的に取得するための ecshop に基づいたモバイル etouch を紹介しました。PHP チュートリアルに興味のある友人に役立つことを願っています。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。