forked from nathard/BookStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
104 lines (82 loc) · 2.19 KB
/
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
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
<?php
include('inc/header.php');
require_once('inc/dbconnect.php');
require_once('inc/functions.php');
?>
<?php
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
} else {
$cart = $_GET['id'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
case 'update':
if ($cart) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
}
$cart = $newcart;
break;
}
$_SESSION['cart'] = $cart;
?><!-- cart actions -->
<div class="center_content">
<div class="left_content">
<div class="title"><span class="title_icon"><img src="images/bullet1.gif" alt="" title="" /></span>My cart</div>
<div class="feat_prod_box_details">
<p>Books are shipped at a flat rate of $4.95 per book.<br />
Prices are GST inclusive.</p>
<?php
echo showCart();
print '<a href="results.php?search='.$searchq.'" class="continue">< continue</a>';
print '<a href="order.php" class="checkout">checkout ></a>';
?>
</div>
<div class="clear"></div>
</div><!--end of left content-->
<?php include('inc/right_content.php'); ?>
<div class="clear"></div>
</div><!--end of center content-->
<?php include('inc/footer.php'); ?>