Esempio n. 1
0
        $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
        $json = new JSON();
        $result['content'] = insert_right_cart_info();
        die($json->encode($result));
    } else {
        ecs_header("Location: flow.php\n");
    }
    exit;
} elseif ($_REQUEST['step'] == 'drop_shopcar') {
    $rec_id = intval($_GET['id']);
    flow_drop_cart_goods($rec_id);
    if ($_GET['ajax']) {
        include_once 'includes/cls_json.php';
        $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
        $json = new JSON();
        $result['content'] = insert_right_cart_info();
        die($json->encode($result));
    } else {
        ecs_header("Location: shopcar.php");
    }
    exit;
} elseif ($_REQUEST['step'] == 'add_favourable') {
    /* 取得优惠活动信息 */
    $act_id = intval($_POST['act_id']);
    $favourable = favourable_info($act_id);
    if (empty($favourable)) {
        show_message($_LANG['favourable_not_exist']);
    }
    /* 判断用户能否享受该优惠 */
    if (!favourable_available($favourable)) {
        show_message($_LANG['favourable_not_available']);
Esempio n. 2
0
 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);
 }