ok

Mini Shell

Direktori : /home2/selectio/www/ramali.in/api/
Upload File :
Current File : /home2/selectio/www/ramali.in/api/checkout.php

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


if($_POST['type']='checkout_order'){
    
// 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['ramali_textiles']['id'];
    $name = $_POST['firstname'];
    $mobile_no = $_POST['mobile_no'];
    $alternate_no = $_POST['alternate_mobile_no'];
    $total_amount = $_POST['total_amount'];
    $delivery_charge = 0;
    $payment_method = 'Not paid';
    $address = $_POST['address'];
    $pincode=$_POST['zip'];
    $country=$_POST['country'];
    $type="Not Paid";
    $payment_status=$_POST['pending'];
    $status='Cancelled';
    $order_status = "0";

// 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`,`order_status`) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
$query->execute(array($user_id,$mobile_no,0,$delivery_charge,0,$payment_method,$address,0,0,$address,$order_status));


$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,0,0));
}

// 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,0,0));

//5) Payments
$query = $pdo->prepare("INSERT INTO `payments`(`payment_amount`, `payment_status`, `itemid`) VALUES (?,?,?)");
$query->execute(array(0,0,$order_id));


// 6) Users Details - Update Here
$query = $pdo->prepare("UPDATE users SET pincode=?,latitude=?,street=? WHERE id=?");
$query->execute(array($pincode,$alternate_no,$country,$user_id));

if($query){    
    $return_arr['order_id']=$order_id;
    $return_arr['amount']=$total_amount;
        $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