-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_cart.php
55 lines (39 loc) · 1.11 KB
/
show_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
<?php
require_once 'functions.php';
session_start();
$new = $_GET['new'];
if ($new) {
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
$_SESSION['items'] = 0;
$_SESSION['total_price'] = 0.00;
}
if (isset($_SESSION['cart'][$new])) {
$_SESSION['cart'][$new]++;
}else{
$_SESSION['cart'][$new] = 1;
}
$_SESSION['total_price'] = calculate_price($_SESSION['cart']);
$_SESSION['items'] = calculate_items($_SESSION['cart']);
}
if ($_POST['submit']) {
foreach ($_SESSION['cart'] as $isbn => $qty) {
if ($_POST[$isbn] == '0') {
unset($_SESSION['cart'][$isbn]);
}else{
$_SESSION['cart'][$isbn] = $_POST[$isbn];
}
}
$_SESSION['total_price'] = calculate_price($_SESSION['cart']);
$_SESSION['items'] = calculate_items($_SESSION['cart']);
}
do_html_header("购物车");
do_html_top();
if ($_SESSION['cart'] && array_count_values($_SESSION['cart'])) {
display_cart($_SESSION['cart'],true);
display_button('checkout.php','结算');
}else{
echo "还没有商品添加到购物车";
}
do_html_footer();
?>