forked from Sanjyotbhangare/Kingsman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mycart.php
84 lines (77 loc) · 1.96 KB
/
mycart.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
session_start();
if($_SESSION['mobno'] === NULL){
session_destroy();
echo"<script>
alert('Login is Required');
window.location.href='face.php';
</script>";
}
if($_SERVER['REQUEST_METHOD']=="POST")
{
if(isset($_POST['add_to_cart']))
{
if($_SESSION['mobno'] === NULL){
session_destroy();
echo"<script>
alert('Login is Required');
window.location.href='face.php';
</script>";
}
if(isset($_SESSION['cart']))
{
$myitems=array_column($_SESSION['cart'],'pid');
if(in_array($_POST['pid'],$myitems))
{
echo"<script>
alert('Item Already Added');
window.location.href='main.php';
</script>";
}
else{
$count=count($_SESSION['cart']);
$_SESSION['cart'][$count]=array('pid'=>$_POST['pid']);
$_SESSION['cart'][$count]['Quantity']=1;
echo"<script>
alert('Item Added');
window.location.href='main.php';
</script>";
}
}
else
{
$_SESSION['cart'][0]=array('pid'=>$_POST['pid']);
$_SESSION['cart'][0]['Quantity']=1;
echo"<script>
alert('Item Added');
window.location.href='main.php';
</script>";
}
}
if(isset($_POST['remove'])){
foreach($_SESSION['cart'] as $key => $value)
{
if($value['pid']==$_POST['pid']){
unset($_SESSION['cart'][$key]);
$_SESSION['cart']=array_values($_SESSION['cart']);
echo"<script>
alert('Item Removed');
window.location.href='cart.php';
</script>";
}
}
}
if(isset($_POST['mod_quantity']))
{
foreach($_SESSION['cart'] as $key => $value)
{
if($value['pid']==$_POST['pid'])
{
$_SESSION['cart'][$key]['Quantity']=$_POST['mod_quantity'];
echo"<script>
window.location.href='cart.php';
</script>";
}
}
}
}