ok
Direktori : /proc/thread-self/root/proc/self/root/home2/selectio/www/thecomponents.in/api/ |
Current File : //proc/thread-self/root/proc/self/root/home2/selectio/www/thecomponents.in/api/checkout-api.php |
<?php session_start(); include "../config/config.php"; if($_POST['type']='checkout_order'){ error_log("form is working"); // Details /* 1) orders - Insert 2) order_items - Insert 3) cart - Delete 3) user_addresses - Insert 4) transactions - Insert 5) payments - Insert 6) users - Update */ $user_id = $_SESSION['caliber']['id']; $name = $_POST['firstname']; $mobile_no = $_POST['mobile_no']; $alternate_no = $_POST['alternate_no']; $delivery_address = $_POST['delivery_address']; $total_amount = $_POST['total_amount_price']; $delivery_charge = 0; $payment_method = "COD"; $address = $_POST['address']; $pincode=$_POST['zip']; $country="No country Details"; $type=''; $payment_status="is padding"; $status='Ordered'; // 1) Orders Details - Insert Here $query = $pdo->prepare("INSERT INTO `orders`(`user_id`, `mobile`, `total`, `delivery_charge`, `final_total`, `payment_method`, `address`, `status`, `active_status`, `order_from`) VALUES (?,?,?,?,?,?,?,?,?,?)"); $query->execute(array($user_id,$mobile_no,$total_amount,$delivery_charge,$total_amount,$payment_method,$address,$status,1,$address)); $order_id = $pdo->lastInsertId(); // 2) Order Items - Insert Here for($i=0;$i<count($_POST['product_id']);$i++){ $product_id = $_POST['product_id'][$i]; $product_variant_id = $_POST['product_id'][$i]; $product_name = $_POST['product_name'][$i]; $product_variant_name = $_POST['product_id'][$i]; $product_qty = $_POST['product_qty'][$i]; $product_sub_total = $_POST['product_sub_total'][$i]; $product_price = $_POST['product_price'][$i]; $query = $pdo->prepare("INSERT INTO `order_items`(`user_id`, `order_id`, `product_id`, `product_variant_id`, `product_name`, `variant_name`, `quantity`, `price`, `discounted_price`, `sub_total`, `status`, `active_status`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"); $query->execute(array($user_id,$order_id,$product_id,$product_variant_id,$product_name,$product_variant_name,$product_qty,$product_price,0,$product_sub_total,1,1)); } // 3) Delete - Cart Items $query = $pdo->prepare("DELETE FROM `cart` WHERE user_id=?"); $query->execute(array($user_id)); //4) user - Address $query = $pdo->prepare("INSERT INTO `user_addresses`(`user_id`,`name`, `mobile`, `alternate_mobile`, `address`, `pincode`,`country`) VALUES (?,?,?,?,?,?,?)"); $query->execute(array($user_id,$name,$mobile_no,$alternate_no,$address,$pincode,$country)); //4)Transcation $query = $pdo->prepare("INSERT INTO `transactions`(`user_id`, `order_id`, `type`,`amount`, `status`) VALUES (?,?,?,?,?)"); $query->execute(array($user_id,$order_id,$type,$total_amount,1)); //5) Payments $query = $pdo->prepare("INSERT INTO `payments`(`payment_amount`, `payment_status`, `itemid`) VALUES (?,?,?)"); $query->execute(array($total_amount,$payment_status,$order_id)); // 6) Users Details - Update Here $query = $pdo->prepare("UPDATE users SET longitude=?,latitude=? WHERE id=?"); $query->execute(array($delivery_address,$alternate_no,$id)); if($query){ $return_arr['order_id']=$order_id; $return_arr['message']='Order Successfully Completed'; $return_arr['status']=200; } else{ $return_arr['message']='Something Went Wrong..'; $return_arr['status']=400; } echo json_encode ($return_arr); } ?>