forked from arjankc/online-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarthandler.php
26 lines (24 loc) · 883 Bytes
/
carthandler.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
<?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']); //counting number of items in the cart
$_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>";
}
//we can empty the cart with session_destroy()
?>