%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/www/website_93b53270/ |
Upload File : |
<?php
include "config.php";
if (isset($_POST['id']) && isset($_POST['quantity'])) {
$productId = $_POST['id'];
$quantity = $_POST['quantity'];
// Add the product to the cart (you can adjust your cart structure as needed)
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
if (!isset($_SESSION['cart'][$productId])) {
$_SESSION['cart'][$productId] = $quantity;
$response = array('status' => 'success', 'message' => 'Product added successfully');
} else {
// If the product already exists in the cart, decrement its quantity by 1
if ($_SESSION['cart'][$productId] >1) {
$_SESSION['cart'][$productId] -= 1;
$response = array('status' => 'success', 'message' => 'Quantity updated successfully');
} else {
// If the quantity is already 1, remove the product from the cart
unset($_SESSION['cart'][$productId]);
$response = array('status' => 'success', 'message' => 'Product removed from cart');
}
}
echo json_encode($response);
} else {
$response = array('status' => 'error', 'message' => 'Invalid request');
echo json_encode($response);
}
?>