-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfirm_checkout.php
123 lines (104 loc) · 3.55 KB
/
confirm_checkout.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
include 'util/UserAuthenticationRequired.php';
?>
<?php
$shipping = $_POST['shipping_address'];
$recv = $_POST['recipient'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>阿寯的美食天地</title>
<link rel="stylesheet" type="text/css" href="semantic/semantic.css">
<link rel="stylesheet" type="text/css" href="styles/glide.core.css">
<link rel="stylesheet" type="text/css" href="styles/glide.theme.css">
<link rel="stylesheet" type="text/css" href="styles/style.css">
<script src="scripts/jquery-2.2.2.js"></script>
<script src="semantic/semantic.js"></script>
<script src="scripts/script.js"></script>
<script src="scripts/glide.js"></script>
<script>
</script>
<style>
</style>
</head>
<body>
<div class="ui container">
<?php
include 'navigation.php';
?>
<?php
include 'util/connect.php';
// 檢查訂單是否有項目
$stmt = $mysqli -> prepare('SELECT COUNT(*) FROM group_12.cart WHERE member = ?');
$stmt -> bind_param('d', $uid);
$stmt -> bind_result($cartItemCount);
$stmt -> execute();
$stmt -> fetch();
$stmt -> close();
if ($cartItemCount == 0) {
echo '<script>alert("購物車裡面沒有東西");';
echo 'window.location.assign("checkout.php");</script>';
exit();
}
// 建立新的 Receipt
$stmt = $mysqli -> prepare('INSERT INTO group_12.receipt(member, recipient, shipping_address) VALUES (?, ?, ?)');
$stmt -> bind_param('dss', $uid, $recv, $shipping);
$stmt -> execute();
$receiptID = $stmt -> insert_id;
$stmt -> close();
// 丟購物車的東西進去!
$stmt = $mysqli -> prepare('INSERT INTO group_12.receipt_item (receipt, item_name, item_price, item_id, quantity)
SELECT ?, products.name, products.price, products.id, quantity FROM group_12.products, group_12.cart
WHERE cart.item = products.id AND cart.member = ?');
$stmt -> bind_param('dd', $receiptID, $uid);
$stmt -> execute();
$stmt -> close();
// 刪除購物車裡面的
$stmt = $mysqli -> prepare('DELETE FROM group_12.cart WHERE member = ?');
$stmt -> bind_param('d', $uid);
$stmt -> execute();
$stmt -> close();
include 'util/close.php';
?>
<div class="ui stacked very padded green segment">
<h2 class="ui green header">購買項目</h2>
<div class="ui green icon message">
<i class="grey checkmark icon"></i>
<div class="content">
<div class="header">
訂購成功!
</div>
<p>你已經成功的訂購我們的產品,你可以選擇立即付款!</p>
</div>
</div>
</div>
<div class="ui very padded red segment">
<h2 class="ui red header">付款</h2>
<form action="pay.php?id=<?=$receiptID?>" method="POST" class="ui form">
<button type="submit" class="ui red basic fluid button">確認付款</button>
</form>
</div>
<div class="ui fluid steps">
<div class="step">
<i class="blue truck icon"></i>
<div class="content">
<div class="title">送貨地址</div>
<div class="description">輸入送貨地址以及收貨人</div>
</div>
</div>
<div class="active step">
<i class="green checkmark icon"></i>
<div class="content">
<div class="title">完成</div>
</div>
</div>
</div>
</div>
</div>
<?php
include 'modals.php';
?>
</body>
</html>