-
Notifications
You must be signed in to change notification settings - Fork 2
/
cart.html
239 lines (236 loc) · 6.09 KB
/
cart.html
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
<!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.0" />
<title>Cart page</title>
<!-- font awesome -->
<link
rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.15.4/css/all.css"
integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm"
crossorigin="anonymous"
/>
<!-- stylesheet -->
<link rel="stylesheet" href="../components/template.css" />
</head>
<style>
* {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}
.container {
width: 100%;
margin: 50px auto;
}
.container > div:nth-child(1) {
margin: 0px auto;
width: fit-content;
}
.displaycart {
margin: 50px auto;
display: flex;
justify-content: center;
}
table {
width: 80%;
padding: 20px;
box-sizing: border-box;
}
th {
font-size: 17px;
font-weight: 700;
letter-spacing: 3px;
line-height: 60px;
border-bottom: 1px solid black;
margin-bottom: 20px;
}
tbody {
padding: 30px 0;
box-sizing: border-box;
margin-top: 20px;
}
td {
width: fit-content;
text-align: center;
}
td:nth-child(2) {
text-align: left;
padding-left: 10px;
}
td:nth-child(2) > p {
font-size: 16px;
width: fit-content;
font-weight: 700;
}
td:nth-child(3) {
padding: 0px 50px;
box-sizing: border-box;
}
td:nth-child(3) > div {
width: fit-content;
margin: 0px auto;
border: 0.3px solid rgba(128, 128, 128, 0.596);
padding: 10px 30px;
box-sizing: border-box;
border-radius: 4px;
}
td:nth-child(2) > button {
width: fit-content;
font-size: 18px;
padding: 5px 15px;
margin: 10px 0;
box-sizing: border-box;
border: 1px solid rgba(0, 0, 0, 0.301);
background-color: transparent;
border-radius: 5px;
font-weight: 350;
}
td:nth-child(4) {
padding: 0px 40px;
font-size: 18px;
}
tbody tr td:nth-child(1) > img {
padding: 30px;
box-sizing: border-box;
height: 25vh;
}
.billing {
width: 80%;
margin: 0px auto;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 15px;
}
.total {
display: flex;
justify-content: space-around;
width: 40%;
font-weight: 700;
}
.billing > div:nth-child(2) {
width: 30%;
font-size: 18px;
}
.btns > a > button {
width: fit-content;
padding: 5px 30px;
box-sizing: border-box;
height: 50px;
color: white;
font-size: 17px;
background-color: #111;
border: none;
border-radius: 5px;
font-weight: 600;
margin: 0px 10px;
}
@media screen and (max-width: 1000px) {
table {
width: 100%;
}
}
</style>
<body>
<div class="navbar"></div>
<div class="container">
<div>
<h1>Cart</h1>
</div>
<div class="displaycart">
<table>
<thead>
<tr>
<th></th>
<th></th>
<th>QUANTITY</th>
<th>TOTAL</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div class="billing"></div>
</div>
<footer></footer>
</body>
</html>
<script type="module">
import {
navwithouttop,
footer,
navfunction,
searchanimation,
} from "../components/script.js";
document.querySelector(".navbar").innerHTML = navwithouttop();
document.querySelector("footer").innerHTML = footer();
let cart = JSON.parse(localStorage.getItem("cartitems"));
const appendcart = (cart, index) => {
let maindiv = document.querySelector("tbody");
maindiv.innerHTML = null;
console.log(cart);
cart.forEach(({ title, dprice, quantity, url }) => {
let tr = document.createElement("tr");
let imgdiv = document.createElement("td");
let img = document.createElement("img");
img.src = url;
imgdiv.append(img);
let namediv = document.createElement("td");
let name = document.createElement("p");
name.textContent = title;
let btn = document.createElement("button");
btn.textContent = "Remove";
btn.addEventListener("click", () => {
deleteitem(index);
});
namediv.append(name, btn);
let quantitydiv = document.createElement("td");
let count = document.createElement("div");
if (quantity == null) {
count.textContent = 1;
}
count.textContent = quantity;
quantitydiv.append(count);
let total = document.createElement("td");
let price = document.createElement("p");
price.textContent = `₹${quantity * dprice}`;
total.append(price);
tr.append(imgdiv, namediv, quantitydiv, total);
maindiv.append(tr);
});
let billing = document.querySelector(".billing");
let sum = 0;
for (var i = 0; i < cart.length; i++) {
sum += cart[i].quantity * cart[i].dprice;
}
let totalprice = sum;
billing.innerHTML = `<div class="total">
<p>Subtotal</p>
<p>₹ ${totalprice}</p>
</div>
<div>
<p>Shipping, taxes and discount codes calculated at checkout.</p>
</div>
<div class="btns">
<a href="#"><button>Update cart</button></a>
<a href="checkout.html"><button>Check out</button></a>
</div>`;
};
appendcart(cart);
const deleteitem = (index) => {
cart.splice(index, 1);
localStorage.setItem("cartitems", JSON.stringify(cart));
appendcart(cart);
};
if (cart.length > 0) {
document.getElementById("indicator").style.display = "block";
} else {
document.getElementById("indicator").style.display = "none";
}
navfunction();
searchanimation();
</script>