-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddtocart.html
More file actions
220 lines (182 loc) · 6.18 KB
/
addtocart.html
File metadata and controls
220 lines (182 loc) · 6.18 KB
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
<!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 to cart</title>
<style>
h1{
text-align: center;
color: white;
padding-bottom: 50px;
}
img{
width: 80px;
height: 80px;
padding: 20px 20px 20px 20px;
}
body{
background-color: #874c62;
}
#showitem{
width: 60%;
/* box-shadow: rgba(0, 0, 0, 0.25) 0px 54px 55px, rgba(0, 0, 0, 0.12) 0px -12px 30px, rgba(0, 0, 0, 0.12) 0px 4px 6px, rgba(0, 0, 0, 0.17) 0px 12px 13px, rgba(0, 0, 0, 0.09) 0px -3px 5px; */
margin: auto;
display: flex;
}
#left{
width: 60%;
}
#right{
width: 40%;
height: 200px;
box-shadow: rgba(0, 0, 0, 0.25) 0px 54px 55px, rgba(0, 0, 0, 0.12) 0px -12px 30px, rgba(0, 0, 0, 0.12) 0px 4px 6px, rgba(0, 0, 0, 0.17) 0px 12px 13px, rgba(0, 0, 0, 0.09) 0px -3px 5px;
margin-top: 50px;
border-radius: 10px;
background-color: white;
}
#maindiv{
width: 90%;
margin: auto;
display: flex;
margin-top: 30px;
margin-bottom: 30px;
border-radius: 10px;
box-shadow: rgba(0, 0, 0, 0.25) 0px 54px 55px, rgba(0, 0, 0, 0.12) 0px -12px 30px, rgba(0, 0, 0, 0.12) 0px 4px 6px, rgba(0, 0, 0, 0.17) 0px 12px 13px, rgba(0, 0, 0, 0.09) 0px -3px 5px;
background-color: white;
}
#div1{
width: 80%;
display: flex;
}
#div2{
width: 20%;
}
h4{
color: #874c62;
padding-top: 25px;
padding-left: 50px;
}
p{
color: #874c62;
padding-top: 31px;
padding-left: 50px;
}
button{
width: 40px;
height: 40px;
border-radius: 5px;
border: 1px solid white;
background-color: #874c62;
color: white;
font-size: x-large;
font-weight: bold;
margin-top: 40px;
margin-left: 30px;
}
button:hover{
background-color: white;
color: #874c62;
border: 1px solid #874c62;
}
#pay{
margin-left: 140px;
width: 100px;
height: 30px;
font-size: medium;
}
#total{
padding-left: 100px;
font-size: large;
font-weight: bold;
}
#showWallet{
color: white;
text-align: center;
}
</style>
</head>
<body>
<h1>Add to cart</h1>
<h4 id="showWallet"></h4>
<div id="showitem">
<div id="left"></div>
<div id="right">
<h4 id="total"></h4>
<button id="pay" onclick="payment()">Pay Now</button>
</div>
</div>
</body>
</html>
<script>
var arr = JSON.parse(localStorage.getItem('addtocart'));
arr.map((e, i) => {
let div = document.createElement("div");
div.setAttribute("id", "maindiv")
let div1 = document.createElement("div");
div1.setAttribute("id", "div1")
let div2 = document.createElement("div");
div2.setAttribute("id", "div2")
let img = document.createElement("img");
img.src = e.image;
let title = document.createElement("h4");
title.innerText = e.name;
let amount = document.createElement("p");
amount.innerText = "Rs." +`${e.price}`;
let button = document.createElement('button');
button.innerText = "✘"
button.onclick = () => {
removecart(e, i)
}
div1.append(img, title, amount);
div2.append(button)
div.append(div1, div2)
document.getElementById("left").append(div)
})
function removecart(e, i){
arr.splice(i, 1);
console.log(arr)
localStorage.setItem('addtocart', JSON.stringify(arr))
window.location.reload();
}
var price = JSON.parse(localStorage.getItem('addtocart'));
var sum = 0;
price.map((e)=>{
sum += e.price;
})
document.getElementById("total").innerText = "Total Amount: " + "Rs. " + sum;
// var amount = JSON.parse(localStorage.getItem('amount'))
// console.log(amount)
// var x = amount - sum
// document.getElementById('showWallet').innerText = "Your Wallet Amount is: " + "Rs." + " " + x;
// console.log(x)
// localStorage.setItem('amount', JSON.stringify(x))
var amount = JSON.parse(localStorage.getItem('amount'))
function payment(){
// console.log(amount)
var x = amount - sum
document.getElementById('showWallet').innerText = "Your Wallet Amount is: " + "Rs." + " " + x;
console.log(x)
localStorage.setItem('amount', JSON.stringify(x))
setTimeout(function(){
alert(`You Paid ${sum}`)
}, 2000)
setTimeout(function(){
alert("Your Order Successfully Placed..!")
}, 4000)
setTimeout(function(){
alert("Your Order is On the Way..!")
}, 6000)
setTimeout(function(){
alert("Order Delivered. Thanks for Purchasing..!")
window.location.href = "shop.html";
}, 8000)
price = 0;
}
window.addEventListener("reload", function(){
var x = amount - sum
document.getElementById('showWallet').innerText = "Your Wallet Amount is: " + "Rs." + " " + x;
console.log(x)
})
</script>