-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart-shipping.php
291 lines (262 loc) · 11.7 KB
/
cart-shipping.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?php
session_start();
//連線到本地資料庫
require_once("pdo-connect.php");
$URL = $_SERVER['PHP_SELF'];//取得當前取得當前php檔名,傳入清空購物車
//購物車商品數量總數計算
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
$cartCount = 0;
}
else{
$cartCount = 0;
foreach ($_SESSION["cart"] as $key => $value1) {
$cartCount+=$value1["num"];
}
}
//搜尋使用者資料
$account = "user";
$useraccount="useraccount";
if (isset($_POST["useraccount"])) {
$useraccount = $_POST["useraccount"];
}
$sql = "SELECT * FROM users WHERE account=? "; //AND valid=1
$stmt = $db_host->prepare($sql);
try {
$stmt->execute([$useraccount]);
$userExist = $stmt->rowCount();
// echo $userExist;
if ($userExist > 0) {
$row = $stmt->fetch();
$id = $row["id"];
$account = $row["account"];
$name = $row["mailing_name"];
$email = $row["mailing_email"];
$phone = $row["mailing_phone"];
$address = $row["mailing_address"];
}
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<meta name="Description" content="MaoBook小組專題報告"/>
<meta name="Content-Language" content="zh-TW">
<meta name="author" content="Team MaoBook"/>
<!-- 網站圖示 -->
<link rel="apple-touch-icon" type="image/png" href="images/logo-nbg.png"/>
<link rel="shortcut icon" type="image/png" href="images/logo-nbg.png"/>
<link rel="mask-icon" type="image/png" href="images/logo-nbg.png"/>
<title>板模</title>
<!-- 板模的css、BS5、fontawesome -->
<?php require_once("style.php"); ?>
<!-- 板模end -->
<style>
.title {
text-shadow: 3px 3px 3px #3335;
color: peru;
}
.CartIcon {
width: 25px;
height: 25px;
}
header a {
text-decoration: none;
position: relative;
}
header span {
display: inline-block;
width: 25px;
height: 25px;
background: darkorange;
color: white;
border-radius: 50%;
text-align: center;
line-height: 25px;
position: absolute;
left: 15px;
top: -10px;
}
.table {
margin-bottom: 80px;
}
.pay {
width: 500px;
height: 200px;
background: #cccccc;
border-radius: 30px;
box-shadow: 12px 12px 7px rgba(0, 0, 0, 0.4);
margin-left: 60px;
margin-top: 80px;
}
.num{
width: 50px;
}
</style>
</head>
<body class="sb-nav-fixed">
<?php require_once("main-nav.php"); ?>
<!-- 本頁 內容 -->
<div id="layoutSidenav_content">
<div class="container px-0 mt-5">
<div class="main px-5">
<header class="d-flex justify-content-between align-items-center mb-3">
<h1 class="title fs-2">購物車清單</h1>
<a class="link-secondary" href="cart-shipping.php"><img class="CartIcon"
src="images/shopping-bag.png"><span><?= $cartCount ?></span></a>
</header>
<div class="d-flex justify-content-end">
<a class="btn btn-secondary mb-5 me-2" href="cart-product-list.php">回商品區</a>
<a id="cleanAll" onClick="return doClean()" class="btn btn-secondary mb-5">清空購物車</a>
</div>
<main>
<table class="table table-hover ">
<thead>
<tr>
<th scope="col">商品</th>
<th class="text-end" scope="col">價格</th>
<th class="text-end" scope="col">數量</th>
<th class="text-end" scope="col">小計</th>
<th class="text-end" scope="col">刪除</th>
</tr>
</thead>
<tbody>
<?php
//從Session抓出資料
$totalPrice = 0;
$deliveryFee = 60; //運費
if (!empty($_SESSION["cart"])):
foreach ($_SESSION["cart"] as $key => $value): ?>
<?php
$totalPrice += $value["price"] * $value["num"];
?>
<tr>
<td class="align-middle"><a href="cart-product-detial.php?name=<?= $value["name"] ?>"><?= $value["name"] ?></a></td>
<td class=" text-end align-middle"><?= $value["price"] ?></td>
<td class="text-end align-middle"><?= $value["num"]?></td>
<td class=" text-end align-middle"><?= $value["price"] * $value["num"] ?></td>
<td class="text-end"><a href="cartCleanItem.php?id=<?= $value["id"] ?>"><i class="far fa-2x fa-trash-alt"></i></a></td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="4" class=" text-end">總計:<?= $totalPrice ?></td>
</tr>
<?php else: ?>
<tr>
<td colspan="5">尚未有訂單</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<div class="row m-0 mb-5 ">
<div class="col-5 p-0">
<h2 class="fs-4 border-bottom pb-2 mb-3 fw-bold">帳單資訊</h2>
<form class="d-grid gap-3 mb-3" action="" method="post" name="form1">
<div>
<label for="useraccount" class="text-danger">請輸入會員帳號</label>
<input name="useraccount" type="text" class="form-control form-control" required>
<button class="btn btn-mao-primary mt-2" type="submit" name="Submit">確認</button>
</div>
</form>
<form class="d-grid gap-3" action="cartSendOder.php" method="post" name="form2">
<?php if (isset($useraccount) && $useraccount === $account): ?>
<div>
<label for="account">會員</label>
<input id="okaccount" name="account" type="text" class=" form-control form-control"
value="<?= $account ?>" readonly>
</div>
<div>
<label for="name">聯絡人</label>
<input value="<?= $name ?>" type="text"
class="form-control form-control" placeholder="name" required name="name">
</div>
<div>
<label for="validationCustom03" class="form-label">詳細地址</label>
<input value="<?= $address ?>" type="text" class="form-control"
id="validationCustom03" placeholder="address" required name="address">
<div class="invalid-feedback">請填入詳細地址</div>
</div>
<div>
<label for="phone">電話</label>
<input value="<?= $phone ?>" name="phone" type="tel"
class="form-control form-control" placeholder="09xxxxxxxx" name="phone">
</div>
<div>
<label for="email">Email</label>
<input value="<?= $email ?>" name="email" class="form-control form-control"
type="email" placeholder="name@example.com" name="email">
</div>
<div class="text-danger">請確認以上配送資訊是否正確,不正確請修改</div>
<?php endif; ?>
</div>
<div class="pay col-5 p-4">
<div>
<div class="row text-end m-0">
<div class="col-10 d-grid gap-3 ">
<div>商品總金額:</div>
<div>運費:</div>
<div>結帳金額:</div>
</div>
<div class="col-2 d-grid gap-3">
<?php if ($totalPrice == 0) {
$deliveryFee = 0;
}
?>
<div>NT$<?= $totalPrice ?></div>
<div>+NT$<?= $deliveryFee ?></div>
<div>NT$<?= $totalPrice + $deliveryFee ?></div>
</div>
</div>
<div class=" d-grid">
<button id="sendorder" onClick="return sendCheck()" type="submit" class="btn btn-mao-primary mt-3">下單購買</button>
</div>
</div>
</div>
</form>
</div>
</main>
</div>
<!-- --><?php //require_once("footer.php"); ?>
</div>
</div>
<!-- 本頁內容 end -->
<?php require_once("JS.php"); ?>
<script>
let count = <?php echo $cartCount ?>;//接住php變數
let cleanAll = document.querySelector("#cleanAll");
let sendoder = document.querySelector("#sendorder");
let okaccount=document.querySelector("#okaccount");
//刪除購物車確認警示
function doClean(){
if(count===0 ){
alert('購物車"沒有"商品 ! ');
}
else if(confirm('確定要清空購物車嗎 ? ')===true) {
document.location.href = "cartCleanAll.php?url=" + location.href;
}
return false;
}
//訂單送出時,確認購物車是否有東西
function sendCheck() {
if (!okaccount) {alert('請確認是否輸入"會員帳號" ! ');}
else if (count === 0) {alert('購物車"沒有"商品 ! ');}
else if(confirm('確定要送出訂單嗎 ? ')===true) {
document.location.href ="cartSendOder.php";
}
}
//接住php變數
function sendCheck() {
if (!okaccount) {alert('請確認是否輸入"會員帳號" ! ');}
else if (count === 0) {alert('購物車"沒有"商品 ! ');}
else if(confirm('確定要送出訂單嗎 ? ')===true) {
document.location.href ="cartSendOder.php";
}
}
</script>
</body>
</html>