-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheckout.html
420 lines (335 loc) · 9.88 KB
/
checkout.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
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<!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</title>
<link rel="stylesheet" href="checkout.css" />
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
/>
<link rel="stylesheet" href="common.css" />
<style>
#body {
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS",
sans-serif;
}
#content {
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS",
sans-serif;
text-align: center;
}
#content > h1 {
margin-bottom: -10px;
}
#product_container {
width: 60%;
border: 1px solid none;
display: flex;
margin: auto;
margin-bottom: 50px;
justify-content: space-around;
}
#product_cart {
display: grid;
border: 1px solid none;
width: 50%;
justify-content: space-around;
border-radius: 10px;
gap: 15px;
}
#head {
font-weight: lighter;
font-size: 20px;
padding: 10px 10px 10px 20px;
}
#product_cart > div {
border: 1px solid none;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f4f4f4;
border-radius: 20px 0px;
height: fit-content;
}
#foot {
margin-left: 20px;
margin-right: 50%;
text-align: center;
}
#product_cart > div > img {
width: 150px;
height: 150px;
border-radius: 20px 0px;
box-shadow: rgba(0, 0, 0, 0.15) 1.95px 1.95px 2.6px;
margin-right: 20px;
}
#product_cart > div > h2 {
margin: 0px 15px;
}
#checkout {
border: 1px solid none;
width: 37%;
padding: 20px;
margin-left: 260px;
background-color: #f4f4f4;
}
#checkout > div {
display: flex;
gap: 30px;
justify-content: space-between;
}
#checkout input {
padding: 10px 20px;
border: none;
width: 80%;
}
#checkout > hr {
margin-bottom: 10px;
}
#checkout > hr + h2 {
margin-bottom: 10px;
}
#input_cart {
margin-bottom: 20px;
}
#Place_order + img {
width: 100%;
}
#input_cart button {
color: white;
background-color: black;
border: none;
cursor: pointer;
padding: 10px 20px;
}
#input_cart button:hover {
color: white;
}
.delet_button {
margin: 5px 20px;
padding: 5px 20px;
background-color: black;
color: white;
margin-right: 30px;
font-size: 18px;
}
#title_cart {
width: 300px;
}
.amount_data h2 {
font-weight: 500;
margin: 5px 0px;
}
#Place_order {
color: white;
background-color: #3d3d3d;
border: none;
cursor: pointer;
padding: 10px 20px;
width: 100%;
}
body {
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS",
sans-serif;
}
#Product_e {
color: black;
background-color: #f4f4f4;
border: none;
cursor: pointer;
padding: 10px 20px;
width: 160px;
}
#img22 {
margin-top: 200px;
width: 500px;
}
</style>
</head>
<body>
<h1 id="head">NORDSTROM</h1>
<div id="content"></div>
<div id="product_container">
<div id="product_cart"></div>
<div id="checkout">
<h2>Cart Details</h2>
<div id="input_cart">
<input type="text" placeholder="Have a Coupan ?" />
<button id="Apply_coupan">Apply</button>
</div>
<hr />
<h2>PRICE DETAILS</h2>
<div class="amount_data">
<h2>Cart Items</h2>
<h2 id="cart_qty">0</h2>
</div>
<div class="amount_data">
<h2>Total MRP</h2>
<h2 id="total_mrp">0</h2>
</div>
<div class="amount_data">
<h2>Discount</h2>
<h2 id="discount">0</h2>
</div>
<hr />
<div>
<h2>Total Amount</h2>
<h2 id="total_amount">0</h2>
</div>
<button id="Place_order">Continue>>></button>
<img
src="https://img.pikbest.com/png-images/20191028/e-commerce-shopping-festival-shopping-gif_2515306.png!bw700"
alt=""
/>
</div>
</div>
<p id="foot">
By placing your order, you agree to the Terms & Conditions and Privacy
Policy of Borderfree from Pitney Bowes, Nordstrom’s international
fulfillment service. Borderfree is an online merchant that is located at
Shelton, US, 06484, 27 Waterview Dr, CT.
</p>
</body>
</html>
<script>
let arr = JSON.parse(localStorage.getItem("cart")) || [];
let displayData = () => {
let cart_products = document.querySelector("#product_cart");
cart_products.innerHTML = "";
if (arr == "") {
let cart_products = document.querySelector("#product_cart");
let div = document.createElement("div");
div.style.padding = "0px 150px";
div.style.alignContent = "center";
let image = document.createElement("img");
image.src =
"https://cdn.dribbble.com/users/887568/screenshots/3172047/ufo.gif";
image.setAttribute("id", "img22");
let ttt = document.createElement("h1");
ttt.innerText = "Cart Is Empty";
ttt.style.color = "rgb(0,0,0)";
div.append(ttt, image);
cart_products.append(div);
}
console.log(cart_products);
arr.map((el, index) => {
let div = document.createElement("div");
div.setAttribute("id", "product");
let img = document.createElement("img");
img.src = el.img;
let title = document.createElement("h2");
title.innerText = el.title;
title.setAttribute("id", "title_cart");
let price = document.createElement("h2");
price.innerText = " ₹ " + el.price;
var select = document.createElement("select");
var option1 = document.createElement("option");
option1.setAttribute("value", 0);
option1.innerText = "Qty:";
var option2 = document.createElement("option");
option2.setAttribute("value", 1);
option2.innerText = "Qty:" + 1;
select.style.width = "60px";
select.style.marginLeft = "30px";
select.style.outline = "none";
select.style.border = "3px solid white";
var option3 = document.createElement("option");
option3.setAttribute("value", 2);
option3.innerText = "Qty:" + 2;
var option4 = document.createElement("option");
option4.setAttribute("value", 3);
option4.innerText = "Qty:" + 3;
var option5 = document.createElement("option");
option5.setAttribute("value", 4);
option5.innerText = "Qty:" + 4;
console.log(option5);
select.append(option2, option3, option4);
select.addEventListener("change", function () {
var selected = select.value;
price.innerHTML = " ₹ " + el.price * selected;
addToArray(el, index, selected);
});
function addToArray(el, index, selected) {
if (selected === "2") {
arrayOfCardToPay.splice(index, 1, el.price * 2);
}
if (selected === "1") {
arrayOfCardToPay.splice(index, 1, el.price * 1);
}
if (selected === "3") {
arrayOfCardToPay.splice(index, 1, el.price * 3);
}
// callToArray(arrayOfCardToPay);
}
let delet = document.createElement("button");
delet.innerText = "Delete";
delet.setAttribute("class", "delet_button");
delet.style.cursor = "pointer";
delet.addEventListener("click", function () {
delete_product(el, index);
});
// let quanti
div.append(img, title, price, select, delet);
cart_products.append(div);
});
};
displayData();
let delete_product = (el, index) => {
arr.splice(index, 1);
localStorage.setItem("cart", JSON.stringify(arr));
window.location.reload();
};
// total_mrp
// discount
// total_amount
//input_cart
let total = 0;
let discount;
let final_total;
let Total_mrp = document.querySelector("#total_mrp");
let discount_mrp = document.querySelector("#discount");
let final = document.querySelector("#total_amount");
Total_mrp.innerText = total.toFixed(2);
document.querySelector("#Apply_coupan").addEventListener("click", coupanData);
function coupanData() {
let applied_coupan = document.querySelector("#input_cart > input").value;
// console.log(applied_coupan)
if (applied_coupan != "Masai50") {
alert("Coupan is Empty");
} else if (applied_coupan != "Masai50") {
alert("Not a Valid Coupan");
}
if (applied_coupan == "Masai50") {
final_total = (total / 100) * 60;
discount = (total - final_total).toFixed(2);
discount_mrp.innerText = ` - ${discount}`;
final.innerText = final_total.toFixed(2);
alert("Coupon Applied Successfully");
}
}
function amountSHow() {
arr.map((el) => {
/// TOTAL MRP ////
let price_ = +el.price;
console.log(price_);
total = total + price_;
Total_mrp.innerText = total;
final.innerText = total;
});
}
amountSHow();
document.querySelector("#Place_order").addEventListener("click", Placeorder);
function Placeorder() {
if (arr == "") {
alert("Please Add Some Product");
} else {
alert("Going for Payment");
window.location.href = "payment.html";
localStorage.clear();
}
}
document.getElementById("cart_qty").innerText = arr.length;
</script>