%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64 User : ndkhermy ( 1200) PHP Version : 8.5.12 Disable Function : NONE Directory : /home1/ndkhermy/public_html/website_6ca89795/api/ |
Upload File : |
<?php
header("Content-Type: application/json");
include("../dbcon.php");
include("auth.php");
define('BASE_URL', 'https://meatandgo.fr/');
function response($status, $message, $data = [])
{
echo json_encode([
"status" => $status,
"message" => $message,
"data" => $data
], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
exit;
}
/*
|--------------------------------------------------------------------------
| Get Primary Address
|--------------------------------------------------------------------------
*/
$addressQry = mysqli_query(
$conn,
"SELECT *
FROM user_address
WHERE user_id='$user_id'
AND is_primary='1'
LIMIT 1"
);
$delivery_address = null;
if(mysqli_num_rows($addressQry) > 0)
{
$address = mysqli_fetch_assoc($addressQry);
$delivery_address = [
"address_id" => $address['id'],
"full_name" => $address['full_name'],
"flat_house" => $address['flat_house'],
"street_name" => $address['street_name'],
"address" => $address['address']
];
}
/*
|--------------------------------------------------------------------------
| Cart Items
|--------------------------------------------------------------------------
*/
$items = [];
$subtotal = 0;
$cartQry = mysqli_query(
$conn,
"SELECT
c.id as cart_id,
c.quantity,
p.*
FROM cart_items c
INNER JOIN areawecover p
ON c.product_id = p.id
WHERE c.user_id='$user_id'
ORDER BY c.id DESC"
);
while($row = mysqli_fetch_assoc($cartQry))
{
$price = (float)$row['price'];
$actual_price = (float)($row['actual_price'] ?? 0);
$offer_percentage = 0;
if(
$actual_price > 0 &&
$actual_price > $price
)
{
$offer_percentage = round(
(
($actual_price - $price)
/
$actual_price
) * 100
);
}
$item_total =
$price *
$row['quantity'];
$subtotal += $item_total;
$items[] = [
"cart_id" => $row['cart_id'],
"product_id" => $row['id'],
"title" => $row['title'],
"weight" => $row['weight'],
"quantity" => $row['quantity'],
"price" => $price,
"actual_price" => $actual_price,
"offer_percentage" => $offer_percentage,
"image" =>
BASE_URL .
"admin/dataimg/" .
$row['image'],
"item_total" => $item_total
];
}
/*
|--------------------------------------------------------------------------
| Charges
|--------------------------------------------------------------------------
*/
$delivery_fee = 5;
$service_fee = 2;
$grand_total =
$subtotal +
$delivery_fee +
$service_fee;
/*
|--------------------------------------------------------------------------
| Response
|--------------------------------------------------------------------------
*/
response(true, "Checkout Loaded Successfully", [
"delivery_address" =>
$delivery_address,
"total_items" =>
count($items),
"items" =>
$items,
"cart_summary" => [
"currency_symbol" =>
$currency_symbol,
"currency_code" =>
$currency_code,
"subtotal" =>
$subtotal,
"delivery_fee" =>
$delivery_fee,
"service_fee" =>
$service_fee,
"grand_total" =>
$grand_total
],
"payment_methods" => [
[
"code" => "online",
"title" => "Online"
],
[
"code" => "cod",
"title" => "Cash On Delivery (COD)"
]
],
"next_api" => [
"place_order_api" =>
BASE_URL .
"api/place_order.php"
]
]);
$conn->close();
?>