forked from Kartikey0813/Masai_CyberPunks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcart.html
388 lines (368 loc) · 9.78 KB
/
vcart.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
<!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>Add cart Page </title>
<style>
table{
/* border: 1px solid red; */
border-collapse: collapse;
width: 81%;
margin: auto;
text-align: center;
}
table thead{
/* border: 1px solid red; */
background: #545871;
/* color: red; */
font-size: 20px;
font-family: system-ui;
width: 100%;
}
table thead th{
/* border: 1px solid red; */
background-color: #545871;
color: black;
font-family:'Courier New', monospace;
}
table tbody td{
padding: 0px;
/* border: 1px solid red; */
}
img{
max-width: 100%;
max-height: 150px;
cursor: pointer;
/* border: 1px solid red; */
}
button{
font-size: 20px;
padding: 1px 11px;
cursor: pointer;
}
span{
display: inline-block;
margin: 0px 10px;
font-size: 25px;
}
.cuppon,.price{
display: flex;
justify-content: space-around;
width: 40%;
margin: auto;
margin-top: 30px;
align-items: center;
}
.price{
margin-top: 0%;
}
.cuppon button{
padding: 5px 10px;
font-weight: 600;
text-transform: capitalize;
}
.cuppon input{
padding: 8px;
font-size: 20px;
/* border: none; */
border-radius: 30px;
height: 10px;
}
.price h3,.price h4{
font-size: 20px;
font-family: monospace;
border-radius: 30px;
color: black;
background-color: #545871;
}
h1{ width:25%;
/* margin: auto; */
/* background-color: white; */
color:black;
padding: 20px;
justify-content: flex-start;
margin-left: 50px;
}
#productLength{
/* border: 2px solid red; */
background-color: #545871;
color: black;
padding: 20px;
}
#vbag{
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 50px;
/* border: 1px solid red; */
/* background-color: #f0f1f7; */
background-color: #545871;
}
#vbag>div:first-child{
width:30%;
justify-content: center;
align-items: center;
padding: 20px;
display: flex;
/* border: 2px solid red; */
justify-content: space-between;
}
#vbag>div:first-child>input{
width:60%;
justify-content: center;
align-items: center;
padding: 20px;
display: flex;
/* border: 2px solid red; */
justify-content: space-between;
}
#vbag>div:first-child>button{
margin-left: 20px;
font-size: 13px;
width: 50%;
/* border: 1px solid red; */
background-color:none;
color:#545871;
padding: 10px;
border-radius: 25px;
}
#vbag>div:first-child>button:hover{
font-size: 13.5px;
}
#vbag>div:nth-child(2){
width: 20%;
justify-content: center;
align-items: center;
margin-top: 50px;
margin-left: 50px;
display: flex;
gap: 10px;
/* border: 2px solid red; */
background-color: #e4e5ed;
border-radius: 30px;
color: white;
padding: 0px;
justify-content: space-between;
}
#vbag>div:nth-child(3){
width:20%;
/* background-color: rgb(184, 206, 240);
background-color: #545871; */
background-color: #e4e5ed;
height: 130px;
border-radius: 30px;
/* border: 2px solid red; */
padding-top: 10px;
/* border: 2px solid red; */
}
#checkout{
/* border: 2px solid red; */
border: none;
background-color: #545871;
color: white;
font-size: 30px;
padding: 10px;
display: block;
margin: auto;
margin-top: 20px;
border-radius: 20px;
}
#bottom{
margin-top: 50px;
width: 100%;
/* background-color: aqua; */
margin: auto;
height: 50px;
}
#bottom > img {
width: 100%;
height: 300px;
margin-top: 30px;
}
#father{
width: 100%;
height: auto;
/* background-color: #545871; */
background-color: #e4e5ed;
}
th,td,tr{
/* background-color: blue; */
width: 150px;
}
td {
width: 30%;
}
td >img{
width: 100%;
height: 150px;
}
</style>
</head>
<body>
<div id="father">
<div id="yourcart">
<h1>Your Cart</h1>
<a href="underline"><p></p></a>
</div>
<div id="vbag">
<div class="cuppon">
<input type="text" id="cupCode">
<button>Apply Coupon code</button>
</div>
<div class="price">
<h3>Total Price</h3> <h3 id="total">0</h3>
</div>
<div class="price">
<h4>Items in cart</h4> <h4 id="productLength"> 0</h4>
</div>
</div>
<table border="1px">
<thead>
<tr>
<th>Img</th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Delete</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<!-- <tr>
<td><img src="https://content.shop4reebok.com/static/Product-EX4296/reebok_EX4296_1.jpg.plp" alt=""></td>
<td>Name of ther product</td>
<td>34394$</td>
<td><button> -</button> <span> 0</span> <button>+</button></td>
<td> <img src="https://media.istockphoto.com/vectors/garbage-bin-sign-vector-id1139466631?k=20&m=1139466631&s=612x612&w=0&h=F3hOMYdQTDn4NFEi94i9StIbDxJ1v7mX79lDxz1cXLk=" alt=""></td>
<td>10$</td>
</tr> -->
</tbody>
</table>
<button id="checkout" onclick="Checkout()">Checkout</button>
</div>
<div id="bottom"><img src="https://lh3.googleusercontent.com/bLAxjlv7H69fL9jqsxJAPV_GegpE_UBZHGPc5WjIPTfWTFDKu8DLbr1X-g1IUXi8mCQ-KXhqvHfhq8YytdgOLu58ZDdPbvhZYTvfrt8bjMG0k5XpCm-3Uu8V19oFpgr26uzy0IaMhw=w2400" alt=""></div>
</body>
</html>
<script>
var totalsum =0;
var mencart = JSON.parse(localStorage.getItem("lobhai"))
displaycart(mencart)
document.getElementById('productLength').innerText=mencart.length;
function displaycart(mencart){
document.querySelector('tbody').innerHTML='';
mencart.forEach(function(elem,index){
let tbody=document.querySelector('tbody');
let tr=document.createElement('tr');
let td=document.createElement('td');
let img=document.createElement('img');
img.setAttribute('src',elem.image_url);
td.append(img);
let td1=document.createElement('td');
td1.innerText=elem.name;
let td2=document.createElement('td');
td2.innerText=elem.price;
let td3=document.createElement('td');
let btn1=document.createElement('button');
btn1.innerText='-';
let span=document.createElement('span');
span.innerText='1';
let btn2=document.createElement('button');
btn2.innerText='+';
td3.append(btn1,span,btn2);
let td4=document.createElement('td');
let img2=document.createElement('img');
img2.setAttribute('src','https://media.istockphoto.com/vectors/garbage-bin-sign-vector-id1139466631?k=20&m=1139466631&s=612x612&w=0&h=F3hOMYdQTDn4NFEi94i9StIbDxJ1v7mX79lDxz1cXLk=')
td4.appendChild(img2);
img2.addEventListener('click',function(){
deleteProduct(elem,index)
total();
})
let td5=document.createElement('td');
td5.innerText=elem.price;
tr.append(td,td1,td2,td3,td4,td5);
tbody.appendChild(tr);
btn2.addEventListener('click',function(){
let acutal=elem.price;
productQuantityPlus(span,td5,acutal)
})
btn1.addEventListener('click',function(){
let acutal=elem.price;
productQuantityMinus(span,td5,acutal)
})
})
}
// delete Product Page
function deleteProduct(elem,index){
mencart.splice(index,1);
localStorage.setItem('mendetail',JSON.stringify(mencart));
displaycart(mencart)
document.getElementById('productLength').innerText=mencart.length;
}
// increase Product quantity
let dataArray=[];
let latestArray=[];
function productQuantityPlus(span,price,acutalPrice){
latestArray=dataArray;
dataArray=[];
let count=+span.innerText;
let acutalData=+acutalPrice;
count++;
span.innerText=count;
let prices=count*acutalData;
price.innerText=prices;
dataArray.push(prices);
total();
}
// decrease product quantity
function productQuantityMinus(span,price,acutalPrice){
let currentPrice=+price.innerText;
let acutalData=+acutalPrice;
let count=+span.innerText;
if(count==1){
count=1;
span.innerText=count;
}
else{
count--;
span.innerText=count;
}
if(currentPrice==acutalData){
price.innerText=acutalData;
}
else{
price.innerText=currentPrice-acutalData;
}
total();
}
// put the total pize of the product
function total(){
let totalData=document.querySelectorAll('tbody td:last-child');
let totalPrice=0;
let priceTag=document.getElementById('total')
totalData.forEach(function(elem){
let data=+elem.innerText
console.log(elem.innerText);
totalPrice+=data;
priceTag.innerText=totalPrice;
})
}
displaycart(mencart)
total();
document.querySelector('button').addEventListener('click',applyCupponCode);
function applyCupponCode(){
let input=document.querySelector('input').value;
let totals;
let totalData=+document.querySelector('#total').innerText;
// console.log(totalData)
if(input =="FLAT10"){
totals= (totalData/100)*90;
document.querySelector('#total').innerText=totals;
}
}
function Checkout(){
window.location.href="addressPage.html"
}
</script>