-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
140 lines (140 loc) · 5.34 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
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
<?php
include_once "./include/header.php";
session_start();
?>
<?php
$conn = mysqli_connect("localhost","root","1234","shopping");
$sql = "select product.photourl, product.name, product.price,
product.delprice, basket.c_quantity, basket.c_no,
basket.c_memberid,basket.c_size, basket.c_color
from product inner join basket
on product.no = basket.c_pno
where basket.c_memberid = '{$_SESSION['userid']}'
";
$result = mysqli_query($conn, $sql);
$list="";
while($row=(mysqli_fetch_array($result))){
//50000 => 50,000
$totalProduct = number_format($row['price']*$row['c_quantity'],0,'.',',');
$totaldelProduct = number_format($row['price']*$row['c_quantity']+$row['delprice'],0,'.',',');
$deleprice = number_format($row['delprice'],0,'.',',');
$price = number_format($row['price'],0,'.',',');
$list = $list."
<tr class='trTwo'>
<td class='tdTwo'><input type='checkbox' checked class='cartcheck'
data-price='{$row['price']}'
data-del='{$row['delprice']}'
data-quan='{$row['c_quantity']}'>
<img src='{$row['photourl']}' width='150'></td>
<td><p id='cartName'>{$row['name']}</p>
*사이즈 : {$row['c_size']} *컬러 :{$row['c_color']}
<td>{$row['c_quantity']}</td>
<td>{$totalProduct}</td>
<td>{$deleprice}</td>
<td><button class='del' data-no='{$row['c_no']}'
onclick='cartdel(this)'>삭제</button></td></td>
</tr>
";
}
?>
<?php
include_once "./include/menu.php";
?>
<div id="newPage">
<div id="cartPage">
<h2>장바구니</h2>
<div id="cartForm">
<table class="cartList" cellspacing="0">
<tr>
<th>상품사진</th>
<th>상품정보</th>
<th>주문수량</th>
<th>가격</th>
<th>배송비</th>
<th>선택</th>
</tr>
<?=$list?>
</table>
</div>
<div id="cartForm1">
<table class="cartList1" cellspacing="0" >
<tr>
<th>총 상품금액</th>
<th rowspan="2"><span>+</span></th>
<th>총 배송비</th>
<th rowspan="2"><span>=</span></th>
<th>결제예정금액</th>
</tr>
<tr>
<td>
<span class="price">
<span id="productprice">97,000</span>원
</span>
</td>
<td>
<span class="price">
<span id="delprice">0</span>원
</span>
</td>
<td>
<span class="price">
<span id="totaprice">97,000</span>원
</span>
</td>
</tr>
</table>
</div>
</div>
</div>
<script>
const checkinputs = document.querySelectorAll('.cartcheck');
checkinputs.forEach(ch=>{
ch.addEventListener('click',totalprice);
})
function totalprice(){
let totalprice = 0;
let totaldel = 0;
let totaltal = 0;
checkinputs.forEach(ch=>{
if(ch.checked){
const {price,del,quan} = ch.dataset;
totalprice += price*quan;
totaldel = Number(del);
}
})
//전체상품가격 + 전체배송료
totaltal = totalprice+totaldel;
document.querySelector('#productprice').innerHTML = totalprice.toLocaleString('ko-KR');
document.querySelector('#delprice').innerHTML = totaldel.toLocaleString('ko-KR');
document.querySelector('#totaprice').innerHTML = totaltal.toLocaleString('ko-KR');
}
totalprice();
async function cartdel(cartlist){
//cart 번호
const {no} = cartlist.dataset;
try{
const res = await fetch(`http://localhost/shopping/process/cartdel_process.php`,{
method: "POST",
header: {
"Content-Type":"application/json",
},
body : JSON.stringify({
c_no: no
})
});
const result = await res.text();
if(result=="yes"){
console.log("삭제");
location.reload();
}else {
console.log("삭제안됨");
}
}
catch(e){
console.log(e);
}
}
</script>
<?php
include_once "./include/footer.php";
?>