ok

Mini Shell

Direktori : /home2/selectio/public_html/thecomponents.in/api/
Upload File :
Current File : /home2/selectio/public_html/thecomponents.in/api/checkout.php

<?php 
session_start();
include "../config/config.php";


if($_POST['type']='checkout_order'){
    
error_log("form is working");
    
    $user_id = $_SESSION['caliber']['id'];
    $name = $_POST['firstname'];
    $mobile_no = $_POST['mobile_no'];
    $alternate_no = $_POST['alternate_mobile_no'];
    $delivery_address = $_POST['delivery_address'];
    $total_amount = $_POST['total_amount'];
    $delivery_charge = 0;
    $payment_method = "COD";
    $address = $_POST['address'];
    $pincode=$_POST['zip'];
    $country=$_POST['country'];
    $type=$_POST['type_payment'];
    $payment_status=$_POST['pending'];
    $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);

}
?>

Zerion Mini Shell 1.0