javascript - ecshop 中如何在猜你喜歡中加入庫存的判斷,庫存小於0就不顯示

來源:互聯網
上載者:User
關鍵字 php javascript
我加了goods_number 但是沒取出來

 /*     *擷取推薦商品(猜你喜歡)     */    function insert_like_product($arr){        $need_cache = $GLOBALS['smarty']->caching;        $need_compile = $GLOBALS['smarty']->force_compile;                $GLOBALS['smarty']->caching = false;        $GLOBALS['smarty']->force_compile = true;                if (!in_array($arr['type'], array('like')))        {            $GLOBALS['smarty']->assign('number', $arr['number']);            return array();        }                static $type_goods = array();        if (empty($type_goods[$arr['type']]))        {            //初始化資料            $type_goods['like']    = array();            $goods_data = array();            $data = read_static_cache('like_product_'.$arr['number']);            if ($data == false)            {                $where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');                $sql   = 'SELECT goods_id, cat_id FROM ' . $GLOBALS['ecs']->table('goods') ." WHERE ".$where." AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";                $like_goods =$GLOBALS['db']->getAll($sql);                foreach($like_goods as $val)                {                    $like = get_category_goods('', $val['cat_id'],20,false);                    foreach($like as $value)                    {                        if(count($goods_data) < $arr['number']){                            $goods_data[] = $value;                            $goods_data = unique_arr($goods_data);                        }                            }                }                write_static_cache('like_product_'.$arr['number'], $goods_data);            }            else            {                $goods_data = $data;            }        }        $GLOBALS['smarty']->assign('like_goods', $goods_data);        $GLOBALS['smarty']->assign('type', $arr['type']);                    $val= $GLOBALS['smarty']->fetch('library/like_product.lbi');                $GLOBALS['smarty']->caching = $need_cache;        $GLOBALS['smarty']->force_compile = $need_compile;                return $val;    }

===================================================================================

/*

 *擷取分類推薦商品 */    function get_category_goods($type = '', $cats = '',$num=0,$status=true, $brand = 0, $min =0,  $max = 0, $ext=''){    $brand_where = ($brand > 0) ? " AND g.brand_id = '$brand'" : '';    $price_where = ($min > 0) ? " AND g.shop_price >= $min " : '';    $price_where .= ($max > 0) ? " AND g.shop_price <= $max " : '';    $sql =  'SELECT g.goods_id, g.goods_name, g.goods_number, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .            "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".            'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' .            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .            'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .            "LEFT JOIN " . $GLOBALS['ecs']->table('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 ' . $brand_where . $price_where . $ext;    $type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion');    if($status)        $num = get_library_number($type2lib[$type]);    switch ($type)    {        case 'best':            $sql .= ' AND is_best = 1';            break;        case 'new':            $sql .= ' AND is_new = 1';            break;        case 'hot':            $sql .= ' AND is_hot = 1';            break;        case 'promote':            $time = gmtime();            $sql .= " AND is_promote = 1 AND promote_start_date <= '$time' AND promote_end_date >= '$time'";            break;    }    if (!empty($cats))    {        $sql .= " AND (g.cat_id=" . $cats . " OR " . get_extension_goods($cats) .")";    }    $order_type = $GLOBALS['_CFG']['recommend_order'];    $sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()';    $res = $GLOBALS['db']->selectLimit($sql, $num);    $idx = 0;    $goods = array();    while ($row = $GLOBALS['db']->fetchRow($res))    {        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]['number']       = $row['goods_number'];//庫存        $goods[$idx]['brief']        = $row['goods_brief'];        $goods[$idx]['brand_name']   = $row['brand_name'];        $goods[$idx]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ?        sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];        $goods[$idx]['market_price'] = price_format($row['market_price']);        $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', array('gid' => $row['goods_id']), $row['goods_name']);        $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);        $idx++;    }    return $goods;} 

回複內容:

我加了goods_number 但是沒取出來

 /*     *擷取推薦商品(猜你喜歡)     */    function insert_like_product($arr){        $need_cache = $GLOBALS['smarty']->caching;        $need_compile = $GLOBALS['smarty']->force_compile;                $GLOBALS['smarty']->caching = false;        $GLOBALS['smarty']->force_compile = true;                if (!in_array($arr['type'], array('like')))        {            $GLOBALS['smarty']->assign('number', $arr['number']);            return array();        }                static $type_goods = array();        if (empty($type_goods[$arr['type']]))        {            //初始化資料            $type_goods['like']    = array();            $goods_data = array();            $data = read_static_cache('like_product_'.$arr['number']);            if ($data == false)            {                $where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');                $sql   = 'SELECT goods_id, cat_id FROM ' . $GLOBALS['ecs']->table('goods') ." WHERE ".$where." AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";                $like_goods =$GLOBALS['db']->getAll($sql);                foreach($like_goods as $val)                {                    $like = get_category_goods('', $val['cat_id'],20,false);                    foreach($like as $value)                    {                        if(count($goods_data) < $arr['number']){                            $goods_data[] = $value;                            $goods_data = unique_arr($goods_data);                        }                            }                }                write_static_cache('like_product_'.$arr['number'], $goods_data);            }            else            {                $goods_data = $data;            }        }        $GLOBALS['smarty']->assign('like_goods', $goods_data);        $GLOBALS['smarty']->assign('type', $arr['type']);                    $val= $GLOBALS['smarty']->fetch('library/like_product.lbi');                $GLOBALS['smarty']->caching = $need_cache;        $GLOBALS['smarty']->force_compile = $need_compile;                return $val;    }

===================================================================================

/*

 *擷取分類推薦商品 */    function get_category_goods($type = '', $cats = '',$num=0,$status=true, $brand = 0, $min =0,  $max = 0, $ext=''){    $brand_where = ($brand > 0) ? " AND g.brand_id = '$brand'" : '';    $price_where = ($min > 0) ? " AND g.shop_price >= $min " : '';    $price_where .= ($max > 0) ? " AND g.shop_price <= $max " : '';    $sql =  'SELECT g.goods_id, g.goods_name, g.goods_number, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .            "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".            'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' .            'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .            'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .            "LEFT JOIN " . $GLOBALS['ecs']->table('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 ' . $brand_where . $price_where . $ext;    $type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion');    if($status)        $num = get_library_number($type2lib[$type]);    switch ($type)    {        case 'best':            $sql .= ' AND is_best = 1';            break;        case 'new':            $sql .= ' AND is_new = 1';            break;        case 'hot':            $sql .= ' AND is_hot = 1';            break;        case 'promote':            $time = gmtime();            $sql .= " AND is_promote = 1 AND promote_start_date <= '$time' AND promote_end_date >= '$time'";            break;    }    if (!empty($cats))    {        $sql .= " AND (g.cat_id=" . $cats . " OR " . get_extension_goods($cats) .")";    }    $order_type = $GLOBALS['_CFG']['recommend_order'];    $sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()';    $res = $GLOBALS['db']->selectLimit($sql, $num);    $idx = 0;    $goods = array();    while ($row = $GLOBALS['db']->fetchRow($res))    {        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]['number']       = $row['goods_number'];//庫存        $goods[$idx]['brief']        = $row['goods_brief'];        $goods[$idx]['brand_name']   = $row['brand_name'];        $goods[$idx]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ?        sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];        $goods[$idx]['market_price'] = price_format($row['market_price']);        $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', array('gid' => $row['goods_id']), $row['goods_name']);        $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);        $idx++;    }    return $goods;} 

你找到了對應的方法,那改了以後就列印下SQL語句調試下吧

insert_like_product函數中where條件加個goods_number>0的判斷啊

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.