-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarthandler.php
More file actions
26 lines (24 loc) · 891 Bytes
/
carthandler.php
File metadata and controls
26 lines (24 loc) · 891 Bytes
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
<?php
session_start();
if (isset($_SESSION['cart'])) {
$checker=array_column($_SESSION['cart'], 'item_name');
if(in_array($_GET['cart_name'], $checker)){
echo "<script>alert('Product Is Already In The Cart');
window.location.href='product.php';
</script>";
}else{
$count=count($_SESSION['cart']);//conta o numero presente de itens no carrinho
$_SESSION['cart'][$count]=array('item_id' => $_GET['cart_id'], 'item_name'=>$_GET['cart_name'], 'item_price'=>$_GET['cart_price'], 'quantity'=>1 );
echo "<script>alert('Product Added');
window.location.href='product.php';
</script>";
}
} else {
$_SESSION['cart'][0]=array('item_id'=>$_GET['cart_id'], 'item_name'=>$_GET['cart_name'], 'item_price'=>$_GET['cart_price'], 'quantity'=>1);
echo "<script>alert('Product Added');
window.location.href='product.php';
</script>";
}
//print_r($_SESSION['cart']);
//session_destroy();
?>