-
Notifications
You must be signed in to change notification settings - Fork 15
/
manage_cart.php
70 lines (65 loc) · 1.56 KB
/
manage_cart.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
session_start();
if($_SERVER['REQUEST_METHOD']=='POST')
{
if(isset($_POST['Add_To_Cart']))
{
if(isset($_SESSION['cart']))
{
$myitems=array_column($_SESSION['cart'], 'Item_name');
if(in_array($_POST['Item_name'],$myitems))
{
echo"<script>
alert('Item already added to cart');
window.location.href= 'menu.php';
</script>";
}
else
{
$count=count($_SESSION['cart']);
$_SESSION['cart'][$count]=array('Item_name'=>$_POST['Item_name'],'price'=>$_POST['price'],'Quantity'=>1);
echo"<script>
alert('Item added to cart');
window.location.href= 'menu.php';
</script>";
}
}
else
{
$_SESSION['cart'][0]=array('Item_name'=>$_POST['Item_name'],'price'=>$_POST['price'],'Quantity'=>1);
echo"<script>
alert('Item added to cart');
window.location.href= 'menu.php';
</script>";
}
}
if(isset($_POST['remove_item']))
{
foreach($_SESSION['cart'] as $key => $value)
{
if($value['Item_name']==$_POST['Item_name'])
{
unset($_SESSION['cart'][$key]);
$_SESSION['cart']=array_values($_SESSION['cart']);
echo"<script>
alert('Item removed');
window.location.href='menu.php';
</script>";
}
}
}
if(isset($_POST['Mod_Quantity']))
{
foreach($_SESSION['cart'] as $key => $value)
{
if($value['Item_name']==$_POST['Item_name'])
{
$_SESSION['cart'][$key]['Quantity']=$_POST['Mod_Quantity'];
echo"<script>
window.location.href='menu.php';
</script>";
}
}
}
}
?>