%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_93b53270/ |
Upload File : |
<?php
include "function.php";
if (isset($_POST['id']) && isset($_POST['quantity'])) {
$productId = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT);
$quantity = filter_input(INPUT_POST, 'quantity', FILTER_VALIDATE_INT);
$total = filter_input(INPUT_POST, 'total', FILTER_VALIDATE_INT);
$sevi_id = filter_input(INPUT_POST, 'sevi_id', FILTER_VALIDATE_INT);
$parts = filter_input(INPUT_POST, 'parts', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY);
$price = filter_input(INPUT_POST, 'price', FILTER_VALIDATE_INT);
$oil_id = filter_input(INPUT_POST, 'oil_id', FILTER_VALIDATE_INT);
// Validate quantity
if (!$quantity || $quantity <= 0) {
$response = array('status' => 'error', 'message' => 'Invalid quantity');
echo json_encode($response);
exit;
}
// Add the product to the cart
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
$productDetails = array(
'price'=> $price,
'parts'=> $parts,
'sevi_id'=> $sevi_id,
'total'=> $total,
'oil_id'=> $oil_id,
'quantity' => $quantity
);
if (!isset($_SESSION['cart'][$productId])) {
$_SESSION['cart'][$productId] = $productDetails;
$response = array('status' => 'success', 'message' => 'Product added successfully');
} else {
// If the product already exists in the cart, update its quantity
$response = array('status' => 'error', 'message' => 'Product already exists in the cart');
}
echo json_encode($response);
} else {
$response = array('status' => 'error', 'message' => 'Invalid request');
echo json_encode($response);
}
?>