<?php
// Example add_food_to_session.php
session_start();

// Simulate database or session storage
if (!isset($_SESSION['food_items'])) {
    $_SESSION['food_items'] = array();
}

// Receive POST data
$food_id = $_POST['food_id'];
$food_name = $_POST['food_name'];
$quantity = $_POST['quantity'];
$cost = $_POST['food_cost'];

// Example: Add or update food in session
if (isset($_SESSION['food_items'][$food_id])) {
    // If food item already exists, add to the existing quantity
    $_SESSION['food_items'][$food_id]['quantity'] += $quantity;
} else {
    // If food item does not exist, create a new entry
    $_SESSION['food_items'][$food_id] = array(
        'id' => $food_id,
        'name' => $food_name,
        'food_cost' => $cost,
        'quantity' => $quantity
    );
}

// Respond with JSON
$response = array('success' => true); // Assuming success for simplicity
header('Content-Type: application/json');
echo json_encode($response);
?>
