当前位置: 首页>>代码示例>>PHP>>正文


PHP addto_cart函数代码示例

本文整理汇总了PHP中addto_cart函数的典型用法代码示例。如果您正苦于以下问题:PHP addto_cart函数的具体用法?PHP addto_cart怎么用?PHP addto_cart使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了addto_cart函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mobile_error

    if ($number < 1) {
        mobile_error('返回上一页', '', '输入的库存数量不对');
    }
    if ($goods_id) {
        clear_cart();
        $state = is_stock($goods_id, $number, $spec);
        if ($state == false) {
            mobile_error('返回上一页', '', '库存不足');
        } elseif ($state === 2) {
            mobile_error('返回上一页', '', '配件不允许单独销售');
        } elseif ($state === 3) {
            mobile_error('返回上一页', '', '商品信息错误');
        } elseif ($state === 4) {
            mobile_error('返回上一页', '', '商品已经下架,无法购买');
        }
        if (!addto_cart($goods_id, $number, $spec)) {
            mobile_error('返回上一页', '', '购买失败,请重新购买');
        } else {
            $goods_order = 1;
            ecs_header('Location: flow.php?act=add_order');
            exit;
        }
    } else {
        mobile_error('返回上一页', '', '参数错误');
    }
} elseif ($_REQUEST['act'] == 'add_order') {
    $cart_goods = cart_goods($flow_type);
    if (empty($cart_goods)) {
        mobile_error('返回首页', 'index.php', '购物车里面无商品');
    } else {
        $smarty->assign('cart_goods', $cart_goods);
开发者ID:netroby,项目名称:ecshop,代码行数:31,代码来源:flow.php

示例2: die

        }
    }
    $result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;
    if ($cp == "add_cart") {
        $result['ctype'] = 1;
    } else {
        $result['ctype'] = 2;
    }
    die($json->encode($result));
} else {
    $goods_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
    if ($goods_id) {
        //16:25 2013-07-13
        //clear_cart();
        $_LANG['shortage'] = "对不起,该商品已经库存不足暂停销售。\n你现在要进行缺货登记来预订该商品吗?";
        if (!addto_cart($goods_id)) {
            //16:25 2013-07-13
            echo '购买失败,请重新购买!';
            exit;
        } else {
            $goods_order = 1;
            //16:25 2013-07-13
            if ($cp == "add_cart") {
                $Loaction = 'cart.php';
            } else {
                $Loaction = 'buy.php?act=checkout';
            }
            ecs_header("Location: {$Loaction}\n");
            exit;
        }
    } else {
开发者ID:nanhuacrab,项目名称:ecshop,代码行数:31,代码来源:buy_bak.php

示例3: add_to_cart

 public static function add_to_cart($goods, $goods_id)
 {
     global $db;
     global $ecs;
     include_once 'includes/cls_json.php';
     include_once 'includes/lib_order.php';
     $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
     if (empty($goods)) {
         $result['error'] = 1;
         return json_encode($result);
     }
     $json = new JSON();
     $goods = $json->decode($goods);
     //检查:如果商品有规格,而post的数据没有规格,把商品的规格属性通过JSON传到前台
     if (empty($goods->spec) and empty($goods->quick)) {
         $sql = "SELECT a.attr_id, a.attr_name, a.attr_type, " . "g.goods_attr_id, g.attr_value, g.attr_price " . 'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' . "WHERE a.attr_type != 0 AND g.goods_id = '" . $goods->goods_id . "' " . 'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
         $res = $db->getAll($sql);
         if (!empty($res)) {
             $spe_arr = array();
             foreach ($res as $row) {
                 $spe_arr[$row['attr_id']]['attr_type'] = $row['attr_type'];
                 $spe_arr[$row['attr_id']]['name'] = $row['attr_name'];
                 $spe_arr[$row['attr_id']]['attr_id'] = $row['attr_id'];
                 $spe_arr[$row['attr_id']]['values'][] = array('label' => $row['attr_value'], 'price' => $row['attr_price'], 'format_price' => price_format($row['attr_price'], false), 'id' => $row['goods_attr_id']);
             }
             $i = 0;
             $spe_array = array();
             foreach ($spe_arr as $row) {
                 $spe_array[] = $row;
             }
             $result['error'] = ERR_NEED_SELECT_ATTR;
             $result['goods_id'] = $goods->goods_id;
             $result['parent'] = $goods->parent;
             $result['message'] = $spe_array;
             return json_encode($result);
         }
     }
     /* 更新:如果是一步购物,先清空购物车 */
     if ($_CFG['one_step_buy'] == '1') {
         clear_cart();
     }
     /* 检查:商品数量是否合法 */
     if (!is_numeric($goods->number) || intval($goods->number) <= 0) {
         $result['error'] = 1;
         $result['message'] = $_LANG['invalid_number'];
     } else {
         // 更新:添加到购物车
         if (addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent)) {
             if ($_CFG['cart_confirm'] > 2) {
                 $result['message'] = '';
             } else {
                 $result['message'] = $_CFG['cart_confirm'] == 1 ? $_LANG['addto_cart_success_1'] : $_LANG['addto_cart_success_2'];
             }
             $result['goods_id'] = stripslashes($goods->goods_id);
             $result['content'] = insert_right_cart_info();
             $result['one_step_buy'] = $_CFG['one_step_buy'];
         } else {
             $result['message'] = $err->last_message();
             $result['error'] = $err->error_no;
             $result['goods_id'] = stripslashes($goods->goods_id);
             if (is_array($goods->spec)) {
                 $result['product_spec'] = implode(',', $goods->spec);
             } else {
                 $result['product_spec'] = $goods->spec;
             }
         }
     }
     $sql = "select * from " . $ecs->table('cart') . " WHERE  session_id='" . SESS_ID . "'";
     $goods = $db->getAll($sql);
     foreach ($goods as $val) {
         $total += $val['goods_price'] * $val['goods_number'];
         //计算额外餐具的价格
         if ($_SESSION['extra_fork'][$val['goods_id']]) {
             $total += $_SESSION['extra_fork'][$val['goods_id']] / 2;
         }
         //蜡烛这玩意 需要在order页面返回给前端添加到订单里,其他商品不需要这么做
         if ($val['goods_id'] == 61) {
             $result['data'] = $val;
         }
     }
     $result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;
     $result['order_total'] = MES_Order::get_total_price_in_cart();
     return json_encode($result);
 }
开发者ID:fromzyy2ann,项目名称:mescake,代码行数:84,代码来源:order.php

示例4: stripslashes

            $result['message'] = $err->last_message();
            $result['error'] = $err->error_no;
            $result['goods_id'] = stripslashes($goods->goods_id);
            if (is_array($goods->spec)) {
                $result['product_spec'] = implode(',', $goods->spec);
            } else {
                $result['product_spec'] = $goods->spec;
            }
        }
    }
    $result['confirm_type'] = !empty($_CFG['cart_confirm']) ? $_CFG['cart_confirm'] : 2;
    die($json->encode($result));
} elseif ($_REQUEST['step'] == 'link_buy') {
    $goods_id = intval($_GET['goods_id']);
    if (!cart_goods_exists($goods_id, array())) {
        addto_cart($goods_id);
    }
    ecs_header("Location:./flow.php\n");
    exit;
} elseif ($_REQUEST['step'] == 'login') {
    include_once 'languages/' . $_CFG['lang'] . '/user.php';
    /*
     * 用户登录注册
     */
    if ($_SERVER['REQUEST_METHOD'] == 'GET') {
        $smarty->assign('anonymous_buy', $_CFG['anonymous_buy']);
        /* 检查是否有赠品,如果有提示登录后重新选择赠品 */
        $sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') . " WHERE session_id = '" . SESS_ID . "' AND is_gift > 0";
        if ($db->getOne($sql) > 0) {
            $smarty->assign('need_rechoose_gift', 1);
        }
开发者ID:will0306,项目名称:bianli100,代码行数:31,代码来源:flow.php

示例5: die

        $result['error'] = 1;
        $result['info'] = '请返回扫描页面,重新扫描';
        die(json_encode($result));
    }
} elseif ($act == 'addcart') {
    include_once 'includes/cls_json.php';
    $result = array('error' => 0, 'content' => '');
    $json = new JSON();
    $info = array(1 => '商品不存在', 2 => '商品缺货', 3 => '商品已下架', 4 => '商品不能单独销售', 5 => '商品没有基本件', 6 => '商品需要用户选择属性');
    if (isset($_SESSION['saodata']) && !empty($_SESSION['saodata'])) {
        $ginfo = get_goods_by_txm(array_keys($_SESSION['saodata']));
        $ok = $fail = array();
        foreach ($ginfo as $key => $val) {
            $txminfo = explode(',', $_SESSION['saodata'][$key]);
            $buynumber = $txminfo[1];
            $goods_id = $val['goods_id'];
            $spec = explode(',', $val['goods_attr_id']);
            if (addto_cart($goods_id, $buynumber, $spec)) {
                unset($_SESSION['saodata'][$key]);
                $ok[] = array('txm' => $key);
            } else {
                $fail[] = array('error' => $err->error_no, 'message' => $info[$err->error_no], 'txm' => $key);
            }
        }
        $result = array('error' => count($fail), 'content' => '提交商品中有部分商品存在异常,无法进入结算!以下为失败原因:', 'fail' => $fail, 'ok' => $ok);
        die($json->encode($result));
    } else {
        $result = array('error' => -1, 'content' => '提交购物车超时,请返回重新扫描!');
        die($json->encode($result));
    }
}
开发者ID:moonlight-wang,项目名称:feilun,代码行数:31,代码来源:scan_list.php

示例6: clear_cart

     } else {
         clear_cart();
     }
 }
 /* 检查:商品数量是否合法 */
 if (!is_numeric($goods->number) || intval($goods->number) <= 0) {
     $result['error'] = 1;
     $result['message'] = $_LANG['invalid_number'];
 } else {
     if (!empty($goods->spec)) {
         foreach ($goods->spec as $key => $val) {
             $goods->spec[$key] = intval($val);
         }
     }
     // 更新:添加到购物车
     if (addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent)) {
         if ($_CFG['cart_confirm'] > 2) {
             $result['message'] = '';
         } else {
             $result['message'] = $_CFG['cart_confirm'] == 1 ? $_LANG['addto_cart_success_1'] : $_LANG['addto_cart_success_2'];
         }
         $result['content'] = insert_cart_info();
         $result['one_step_buy'] = $_CFG['one_step_buy'];
     } else {
         $result['message'] = $err->last_message();
         $result['error'] = $err->error_no;
         $result['goods_id'] = stripslashes($goods->goods_id);
         if (is_array($goods->spec)) {
             $result['product_spec'] = implode(',', $goods->spec);
         } else {
             $result['product_spec'] = $goods->spec;
开发者ID:firsteam,项目名称:falcons,代码行数:31,代码来源:flow.php

示例7: switch

require EC_PATH . '/includes/init.php';
GZ_Api::authSession();
include_once EC_PATH . '/includes/lib_order.php';
if (empty($tmp[0])) {
    GZ_Api::outPut(101);
}
switch ($tmp[0]) {
    case 'create':
        $goods_id = _POST('goods_id', 0);
        $goods_number = _POST('number', 0);
        $goods_spec = _POST('spec', array());
        if (!$goods_number || !$goods_id) {
            GZ_Api::outPut(8);
        }
        // 更新:添加到购物车
        if (addto_cart($goods_id, $goods_number, $goods_spec)) {
            GZ_Api::outPut(array());
        } else {
            GZ_Api::outPut(14);
        }
        break;
    case 'update':
        $rec_id = _POST('rec_id', 0);
        $new_number = _POST('new_number', 0);
        if ($new_number < 1 || !$rec_id) {
            GZ_Api::outPut(101);
        }
        $goods_number = array($rec_id => $new_number);
        flow_update_cart($goods_number);
        $cart_goods = get_cart_goods();
        GZ_Api::outPut($cart_goods['total']);
开发者ID:dx8719,项目名称:ECMobile_Universal,代码行数:31,代码来源:cart.php

示例8: elseif

        echo "<script>alert('登录失败,请输入正确的用户名跟密码');</script>";
    }
} elseif ($action == 'select_goods') {
    $goods_id = trim($_GET['goods_id']);
    $goods = get_goods_info($goods_id);
    //print_r($goods);
    $shop_price = $goods['shop_price'];
    echo $shop_price;
} elseif ($action == 'addtocar') {
    include_once ROOT_PATH . 'includes/lib_transaction.php';
    $goods_id = trim($_GET['goods_id']);
    $addr_radio = trim($_GET['addr_radio']);
    //echo $goods_id;  echo $addr_radio;
    $result = array();
    // 更新:添加到购物车
    if (addto_cart($goods_id, 1, $result, "")) {
        //echo "成功";
        if ($_CFG['cart_confirm'] > 2) {
            $result['message'] = '';
        } else {
            $result['message'] = $_CFG['cart_confirm'] == 1 ? $_LANG['addto_cart_success_1'] : $_LANG['addto_cart_success_2'];
        }
        $result['content'] = insert_cart_info();
        $result['one_step_buy'] = $_CFG['one_step_buy'];
    } else {
        echo "false";
        exit;
    }
    //ccx 2014-12-17 获取会员表当中的用户的用户名和电话
    $sql = "SELECT user_name, mobile_phone FROM " . $ecs->table('users') . " WHERE user_id = " . $_SESSION['user_id'];
    $user_message = $db->getRow($sql);
开发者ID:dlpc,项目名称:ecshop,代码行数:31,代码来源:christmas_activity.php

示例9: check_goods_store

function check_goods_store($rec_id, $num)
{
    $return = array('mes' => '', 'number' => 1);
    $num = intval(make_semiangle($num));
    $rec_id = intval($rec_id);
    if ($num <= 0 && !is_numeric($num)) {
        $return['mes'] = '所填数字必须是正整数!';
        return $return;
    }
    if ($rec_id <= 0) {
        $return['mes'] = '参数错误!';
        return $return;
    }
    //查询:
    $sql = "SELECT `goods_id`, `goods_attr_id`, `product_id`, `extension_code` FROM" . $GLOBALS['ecs']->table('cart') . " WHERE rec_id='{$rec_id}' AND session_id='" . SESS_ID . "'";
    $goods = $GLOBALS['db']->getRow($sql);
    if (!$goods) {
        addto_cart($rec_id, $num);
        $sql = "SELECT `rec_id`,`goods_id`, `goods_attr_id`, `product_id`, `extension_code` FROM" . $GLOBALS['ecs']->table('cart') . " WHERE goods_id='{$rec_id}' AND session_id='" . SESS_ID . "'";
        $goods = $GLOBALS['db']->getRow($sql);
        $rec_id = $goods['rec_id'];
        $return['rec_id'] = $goods['rec_id'];
    }
    $sql = "SELECT g.goods_name, g.goods_number " . "FROM " . $GLOBALS['ecs']->table('goods') . " AS g, " . $GLOBALS['ecs']->table('cart') . " AS c " . "WHERE g.goods_id = c.goods_id AND c.rec_id = '{$rec_id}'";
    $row = $GLOBALS['db']->getRow($sql);
    //查询:系统启用了库存,检查输入的商品数量是否有效
    if (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] != 'package_buy') {
        if ($row['goods_number'] < $num) {
            $return['mes'] = "非常抱歉,您选择的商品" . $row['goods_name'] . " 的库存数量不足 , 您最多只能购买 " . $row['goods_number'] . " 件。";
            $return['number'] = $row['goods_number'];
            return $return;
        }
        /* 是货品 */
        $goods['product_id'] = trim($goods['product_id']);
        if (!empty($goods['product_id'])) {
            $sql = "SELECT product_number FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '" . $goods['goods_id'] . "' AND product_id = '" . $goods['product_id'] . "'";
            $product_number = $GLOBALS['db']->getOne($sql);
            if ($product_number < $num) {
                $return['mes'] = "非常抱歉,您选择的商品" . $row['goods_name'] . " 的库存数量只有 " . $row['product_number'] . ",您最多只能购买 " . $row['product_number'] . " 件。";
                $return['number'] = $row['product_number'];
                return $return;
            }
        }
    } elseif (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] == 'package_buy') {
        if (judge_package_stock($goods['goods_id'], $num)) {
            $return['mes'] = "非常抱歉,库存数量不足,请减少购买数购买。";
            return $return;
        }
    }
    return $return;
}
开发者ID:will0306,项目名称:bianli100,代码行数:51,代码来源:cart.php


注:本文中的addto_cart函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。