%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : 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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/public_html/website_6ca89795/api/cart.php
<?php

header("Content-Type: application/json");

include("../dbcon.php");
include("auth.php");

define('BASE_URL', 'https://meatandgo.fr/');

if (empty($user_id)) {

    echo json_encode([
        "status" => false,
        "message" => "Invalid User"
    ]);
    exit;
}

/*
|--------------------------------------------------------------------------
| Currency Settings
|--------------------------------------------------------------------------
*/

$currency_symbol = '';
$currency_code = '';

$settingQry = mysqli_query(
    $conn,
    "SELECT currency_symbol,currency_code
     FROM app_setting
     LIMIT 1"
);

if ($settingQry && mysqli_num_rows($settingQry) > 0) {

    $setting = mysqli_fetch_assoc($settingQry);

    $currency_symbol = $setting['currency_symbol'];
    $currency_code = $setting['currency_code'];
}

/*
|--------------------------------------------------------------------------
| Primary Address
|--------------------------------------------------------------------------
*/

$delivery_address = null;

$addressQry = mysqli_query(
    $conn,
    "SELECT *
     FROM user_address
     WHERE user_id='$user_id'
     AND is_primary='1'
     LIMIT 1"
);

if ($addressQry && mysqli_num_rows($addressQry) > 0) {

    $addr = mysqli_fetch_assoc($addressQry);

    $delivery_address = [

        "address_id"  => $addr['id'],
        "full_name"   => $addr['full_name'],
        "flat_house"  => $addr['flat_house'],
        "street_name" => $addr['street_name'],
        "address"     => $addr['address']
    ];
}

/*
|--------------------------------------------------------------------------
| Cart Items
|--------------------------------------------------------------------------
*/

$items = [];

$subtotal = 0;

$sql = "
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
";

$query = mysqli_query($conn, $sql);

while ($row = mysqli_fetch_assoc($query)) {

    $price = (float)$row['price'];

    $actual_price = (float)$row['actual_price'];

    $quantity = (int)$row['quantity'];

    $itemTotal = $price * $quantity;

    $subtotal += $itemTotal;

    $offer_percentage = 0;

    if (
        $actual_price > 0 &&
        $price > 0 &&
        $actual_price > $price
    ) {

        $offer_percentage = round(
            (
                ($actual_price - $price)
                /
                $actual_price
            ) * 100
        );
    }

    $stock = (int)$row['stock'];

    $low_stock_message = '';

    if ($stock <= 0) {

        $low_stock_message = 'Out Of Stock';

    } elseif ($stock <= 10) {

        $low_stock_message =
            'Only ' . $stock . ' Left';
    }

    $items[] = [

        "cart_id" => $row['cart_id'],

        "product_id" => $row['id'],

        "title" => $row['title'],

        "price" => $price,

        "actual_price" => $actual_price,

        "offer_percentage" => $offer_percentage,

        "currency_symbol" => $currency_symbol,

        "currency_code" => $currency_code,

        "quantity" => $quantity,

        "weight" => $row['weight'] ?? '',

        "stock" => $stock,

        "low_stock_message" => $low_stock_message,

        "image" =>
            BASE_URL .
            "admin/dataimg/" .
            $row['image'],

        "item_total" => $itemTotal
    ];
}

/*
|--------------------------------------------------------------------------
| Cart Summary
|--------------------------------------------------------------------------
*/

$delivery_fee = 5;
$service_fee = 2;

$grand_total =
    $subtotal +
    $delivery_fee +
    $service_fee;

/*
|--------------------------------------------------------------------------
| Response
|--------------------------------------------------------------------------
*/

echo json_encode([

    "status" => true,

    "message" => "Cart Loaded Successfully",

    "logged_user" => [

        "id" => $user_id,

        "username" => $username,

        "email" => $email
    ],

    "delivery_address" => $delivery_address,

    "cart_summary" => [

        "currency_symbol" => $currency_symbol,

        "currency_code" => $currency_code,

        "subtotal" => $subtotal,

        "delivery_fee" => $delivery_fee,

        "service_fee" => $service_fee,

        "grand_total" => $grand_total
    ],

    "total_items" => count($items),

    "items" => $items

], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);

$conn->close();

?>

VaKeR 2022