-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage_cart.php
39 lines (32 loc) · 937 Bytes
/
manage_cart.php
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
<?php
require "config.php";
require "functions.php";
require "add_cart_func.php";
try {
$pid = get_safe_value($con, $_POST['pid']);
$qty = get_safe_value($con, $_POST['qty']);
$type = get_safe_value($con, $_POST['type']);
$productSoldQtyByProductId = productSoldQtyByProductId($con, $pid);
$productQty = productQty($con, $pid);
$pending_qty = $productQty - $productSoldQtyByProductId;
if ($qty > $pending_qty && $type !== 'remove') {
echo "not_avaliable";
exit;
}
$obj = new add_to_cart();
switch ($type) {
case 'add':
$obj->addProduct($pid, $qty);
break;
case 'remove':
$obj->removeProduct($pid);
break;
case 'update':
$obj->updateProduct($pid, $qty);
break;
}
echo $obj->totalProduct();
} catch (Exception $e) {
echo 'An error occurred: ' . $e->getMessage();
}
?>