-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCartFunction.php
More file actions
105 lines (94 loc) · 2.91 KB
/
CartFunction.php
File metadata and controls
105 lines (94 loc) · 2.91 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
session_start();
include_once("Connection.php");
if(!isset($_SESSION['admin']))
{
echo "<script>alert('You must be login add product to cart')</script>";
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
}
else
{
include_once("Connection.php");
if(isset($_GET['ma'])){
$id = $_GET['ma'];
}
if(isset($_GET['action'])){
$action = ($_GET['action']);
}
else
{
$action='add';
}
if(isset($_GET['quantity'])){
$quantity = $_GET['quantity'];
}
else
{
$quantity=1;
}
if($quantity<=0)
{
$quantity=1;
}
$result = pg_query($conn,"SELECT * FROM product where proid='$id'");
if($result)
{
$product = pg_fetch_assoc($result);
}
$item = [
'id'=>$product['proid'],
'name'=>$product['proname'],
'image'=>$product['proimage'],
'price'=>$product['price'],
'quantity'=>$quantity
];
if($action == 'add')
{
if(isset($_SESSION['cart'][$id])){
if($quantity > $product['proqty'])
{
echo "<script>alert('Your quantity is bigger than the quantity in our stock.')</script>";
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
}
else
{
$_SESSION['cart'][$id]['quantity'] += $quantity;
echo "<script>alert('Add Product to cart successful')</script>";
echo '<meta http-equiv="refresh" content="0;URL=index.php?page=viewcart">';
}
}
else
{
if($quantity > $product['proqty'])
{
echo "<script>alert('Your quantity is bigger than the quantity in our stock.')</script>";
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
}
else
{
$_SESSION['cart'][$id]= $item;
echo "<script>alert('Add Product to cart successful')</script>";
echo '<meta http-equiv="refresh" content="0;URL=index.php?page=viewcart">';
}
}
}
if($action=='update')
{
if($_GET["quantity"] > $product['proqty'])
{
echo "<script>alert('Your quantity is bigger than the quantity in our stock.')</script>";
echo '<meta http-equiv="refresh" content="0;URL=index.php?page=viewcart">';
}
else
{
$_SESSION['cart'][$id]['quantity'] = $quantity;
echo '<meta http-equiv="refresh" content="0;URL=index.php?page=viewcart">';
}
}
if($action=='delete')
{
unset($_SESSION['cart'][$id]);
echo '<meta http-equiv="refresh" content="0;URL=index.php?page=viewcart">';
}
}
?>