-
Notifications
You must be signed in to change notification settings - Fork 0
/
gestioneCarrello.php
executable file
·51 lines (45 loc) · 1.41 KB
/
gestioneCarrello.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
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require_once 'bootstrap.php';
if (isset($_POST["currentVal"])) {
$productId = $_POST["productId"];
$currentVal = $_POST["currentVal"];
if (isUserLoggedIn()) {
$update = $dbh->updateCartProductsQuantity($productId, $currentVal);
print($update);
} else {
$prodotto = $dbh->getProductById($productId);
$update = updateCartProductsQuantity($productId, $currentVal, $prodotto["quantità"]);
print($update);
}
}
if (isset($_POST["itemToDelete"])) {
$productId = $_POST["itemToDelete"];
if (isUserLoggedIn()) {
$productId = $_POST["itemToDelete"];
$dbh->deleteItemFromCart($productId);
} else {
deleteProductFromCart($productId);
}
}
if (isset($_POST["itemToAdd"])) {
//se l'utente è loggato
$productId = $_POST["itemToAdd"];
if (isUserLoggedIn()) {
$productId = $_POST["itemToAdd"];
$insert = $dbh->insertProductInCart($_SESSION["id"], $productId);
print($insert);
} else {
$prodottoDB = $dbh->getProductById($productId);
$insert = insertProductsInCart($prodottoDB, $prodottoDB["quantità"]);
print($insert);
}
}
if(isset($_POST["cartQuantity"])){
if (isUserLoggedIn()) {
$quantità = $dbh->getItemsQuantityInCart($_SESSION["id"]);
print($quantità[0]["quantità"]);
} else {
print (getItemsQuantityInCart());
}
}
?>