diff --git a/api/cart_add.php b/api/cart_add.php index 663073c..eeae506 100644 --- a/api/cart_add.php +++ b/api/cart_add.php @@ -12,17 +12,29 @@ header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers $databaseService = new DatabaseService(); $conn = $databaseService->getConnection(); -$sid = trim($_POST['sid']); $pid = trim($_POST['pid']); +$price = trim($_POST['price']); $qty = trim($_POST['qty']); -$_SESSION['CART'][] = array("pid" => intval($pid), "qty" => intval($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" => $_SESSION['CART'] + "cart" => array_values($_SESSION['CART']) )); ?> diff --git a/api/cart_del.php b/api/cart_del.php new file mode 100644 index 0000000..97ad48b --- /dev/null +++ b/api/cart_del.php @@ -0,0 +1,32 @@ +getConnection(); + +$pid = trim($_POST['pid']); + +foreach($_SESSION['CART'] as $k => $item) { + if($item['pid'] == $pid) { + unset($_SESSION['CART'][$k]); + } +} + +//print_r($_SESSION['CART']); +http_response_code(200); +echo json_encode( + array( + "status" => 200, + "cart" => array_values($_SESSION['CART']) + )); + +?> + diff --git a/components/breadcrumb/breadcrumb.html b/components/breadcrumb/breadcrumb.html index 063dcd5..6800eaa 100644 --- a/components/breadcrumb/breadcrumb.html +++ b/components/breadcrumb/breadcrumb.html @@ -17,6 +17,10 @@ if($getQ[1]) {$levels[1] = array($getQ[2], '/acquistare/'.$getQ[1].'/'.$getQ[2]);} break; + case 'carrello': + $levels[0] = array('carrello', '/carrello'); + break; + case 'due-cucchiai-di-salute': $levels[0] = array('raccontare', '/raccontare'); $levels[1] = array('Due cucchiai di salute', '/due-cucchiai-di-salute'); diff --git a/components/buy/buy.html b/components/buy/buy.html index 8709186..a635c3e 100644 --- a/components/buy/buy.html +++ b/components/buy/buy.html @@ -99,7 +99,7 @@ - continua gli acquisti + concludi ordine @@ -108,3 +108,6 @@ + diff --git a/components/buy/buy.js b/components/buy/buy.js index 0354a9c..216af6e 100644 --- a/components/buy/buy.js +++ b/components/buy/buy.js @@ -50,11 +50,9 @@ $(document).ready( () => { modalImage.prop('src', `/images/products/${pid}.png`) modalName.text(name) modalQty.text(`Quantità : ${selectedQty}`) - modalTotal.text(`Costo totale: ${new Intl.NumberFormat('en-US', { style: 'currency', currency: 'EUR'}).format( price * selectedQty)}`) - - Apis.addToCart(null, pid, selectedQty).then( (data) => { - console.log(data) + modalTotal.text(`Costo totale: ${new Intl.NumberFormat('it-IT', { style: 'currency', currency: 'EUR'}).format( price * selectedQty)}`) + Apis.addToCart(pid, price, selectedQty).then( (data) => { const headerCart = $('.component-header .cart-cta .counter') if(headerCart.length) { headerCart.text(data.cart.length) diff --git a/components/cart/cart.html b/components/cart/cart.html new file mode 100644 index 0000000..6581a3c --- /dev/null +++ b/components/cart/cart.html @@ -0,0 +1,75 @@ + + + +