Home  >  Article  >  Backend Development  >  The mobile etouch based on ecshop implements dynamic acquisition of classified product lists

The mobile etouch based on ecshop implements dynamic acquisition of classified product lists

WBOY
WBOYOriginal
2016-07-29 08:57:051547browse

Modify the file category.php

Two key places need to be modified

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

There is also a function called category_get_goods. This function adds a new field collect return field that can be used to determine whether it has been collected when rendering the front-end page view. And different styles are displayed and different event functions are bound depending on whether it is collected or not

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

Client js code reference

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

Summary

I used to like PHP very much. I worked on it for a while, so I can basically understand mysql in PHP code. Also learned
Children's shoes without PHP basics can learn PHP basics first
Now the blogger is working hard to specialize in front-end and back-end. Recently, he has learned the new APIs of javascript and html5.
Record your work

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

The above introduces the mobile terminal etouch based on ecshop to dynamically obtain the list of classified products, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP学习笔记-PHP语言基础3Next article:Nginx-配置误区