-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcartQtyUpdateProcess.php
More file actions
47 lines (39 loc) · 1.59 KB
/
cartQtyUpdateProcess.php
File metadata and controls
47 lines (39 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
include "db/connections.php";
if (isset($_GET["qty"]) && isset($_GET["id"])) {
$qty = $_GET["qty"];
$cid = $_GET["id"];
if (empty($qty)) {
echo "Invalid request";
} else if ($qty < 1) {
echo "Invalid Quantity";
} else {
// Get cart item details
$cartRs = Database::search("SELECT * FROM `cart` WHERE `id` = '$cid'");
$cartNum = $cartRs->num_rows;
if ($cartNum > 0) {
$cartRow = $cartRs->fetch_assoc();
$stockId = $cartRow["product_id"]; // Assuming you have a "product_id" column in your cart table
// Get product stock details
$stockRs = Database::search("SELECT * FROM `products` WHERE `id` = '$stockId'");
if ($stockRs->num_rows > 0) {
$stock = $stockRs->fetch_assoc();
// Check if available stock is enough
if ($stock["qty"] >= $qty) {
// Update cart quantity
Database::iud("UPDATE `cart` SET `qty` = '$qty' WHERE `id` = '$cid'");
echo "Updated";
} else {
echo "Not enough stock available."; // Handle the scenario where stock is insufficient
}
} else {
echo "Product not found."; // Handle the scenario where the product is not found
}
} else {
echo "Cart item not found."; // Handle the scenario where the cart item is not found
}
}
} else {
echo "Something went wrong.";
}
?>