>  기사  >  백엔드 개발  >  ecshop 기반의 모바일 etouch는 분류된 상품 목록의 동적 획득을 구현합니다.

ecshop 기반의 모바일 etouch는 분류된 상품 목록의 동적 획득을 구현합니다.

WBOY
WBOY원래의
2016-07-29 08:57:051547검색

category.php 파일 수정

두 곳을 수정해야 합니다

<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으로 문의하세요.