diff --git a/api/cart_qty_update.php b/api/cart_qty_update.php new file mode 100644 index 0000000..1a8e28b --- /dev/null +++ b/api/cart_qty_update.php @@ -0,0 +1,42 @@ +getConnection(); + +$pid = trim($_POST['pid']); +$price = trim($_POST['price']); +$qty = trim($_POST['qty']); + +$exists = false; + +foreach($_SESSION['CART'] as $k => $item) { + if($item['pid'] == $pid) { + $_SESSION['CART'][$k]['qty'] = intval($qty); + $exists = true; + } +} + +if(!$exists) { + $_SESSION['CART'][] = array("pid" => intval($pid), "price" => intval($price), "qty" => intval($qty)); +} + +//print_r($_SESSION['CART']); +http_response_code(200); +echo json_encode( + array( + "status" => 200, + "cart" => array_values($_SESSION['CART']) + )); + +?> + diff --git a/components/cart/cart.html b/components/cart/cart.html index 8067854..de5bf24 100644 --- a/components/cart/cart.html +++ b/components/cart/cart.html @@ -13,11 +13,11 @@