-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcart.html
190 lines (138 loc) · 8.54 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
<!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>Document</title>
<link rel="stylesheet" href="cart.css">
<style>
</style>
</head>
<body>
<nav id="miniNav">
<span><img src="data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHg9IjBweCIgeT0iMHB4IiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIiB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMzIgMzIiPjxzdHlsZT4uc3R5bGUwe2ZpbGw6ICM3Nzc3Nzc7fTwvc3R5bGU+PHBhdGggZD0iTTMwLjgyMSAxNy43NDZsLTMuMS0zLjMyMnYtMC4w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></span>
<span> Home</span>
<span><img style="width: 0.8%;" src="data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHg9IjBweCIgeT0iMHB4IiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIiB3aWR0aD0iMTcuMyIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDE3LjMgMzIiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDE3LjMgMzIiPjxzdHlsZT4uc3R5bGUwe2ZpbGw6ICM3Nzc3Nzc7fTwvc3R5bGU+PHBhdGggZD0iTTE2LjksMTUuMUwyLjMsMC40Yy0wLjUtMC41LTEuNC0wLjUtMS45LDBzLTAuNSwxLjQsMCwxLjlMMTQuMSwxNkwwLjQsMjkuN2MtMC41LDAuNS0wLjUsMS40LDAsMS45czEuNCwwLjUsMS45LDAgbDE0LjctMTQuN0MxNy41LDE2LjQsMTcuNSwxNS42LDE2LjksMTUuMUwxNi45LDE1LjF6IiBjbGFzcz0ic3R5bGUwIi8+PC9zdmc+" alt=""></span>
<span >Items</span>
<a href="cart.html" style="text-decoration: none;"><span><img style="width: 0.8%;" src="data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHg9IjBweCIgeT0iMHB4IiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIiB3aWR0aD0iMTcuMyIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDE3LjMgMzIiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDE3LjMgMzIiPjxzdHlsZT4uc3R5bGUwe2ZpbGw6ICM3Nzc3Nzc7fTwvc3R5bGU+PHBhdGggZD0iTTE2LjksMTUuMUwyLjMsMC40Yy0wLjUtMC41LTEuNC0wLjUtMS45LDBzLTAuNSwxLjQsMCwxLjlMMTQuMSwxNkwwLjQsMjkuN2MtMC41LDAuNS0wLjUsMS40LDAsMS45czEuNCwwLjUsMS45LDAgbDE0LjctMTQuN0MxNy41LDE2LjQsMTcuNSwxNS42LDE2LjksMTUuMUwxNi45LDE1LjF6IiBjbGFzcz0ic3R5bGUwIi8+PC9zdmc+" alt=""></span>
<span class="collor">Cart</span></a>
</nav>
<div class="container">
</div>
</body>
</html>
<script>
let cart_data=JSON.parse(localStorage.getItem("cart"))||[]
console.log(cart_data)
display_list(cart_data)
function display_list(cart_data){
document.querySelector(".container").innerHTML=""
let card_list=
`
<div class="cardList">
${
cart_data.map((elem,i)=>
creating_card(elem,i)
)
}
</div>
`
document.querySelector(".container").innerHTML=card_list
}
function creating_card(elem,i){
let card=`
<div id="container" >
<div id="cart-data">
<div id="data-name">
<p>Product Image</p>
<p id="pro">Product name</p>
<p >Quantity</p>
<p>Price</p>
</div>
<hr>
<div id="four-div">
<div class="item-data">
<div id="data-img">
<img src="${elem.image}"/>
</div>
</div>
<div class="item-data">
<h3>${elem.name}</h3>
</div>
<div class="item-data">
<select name="" id="selecting" onchange="change_quantity(event,${i})">
<option value="1" ${elem.quantity==1 ? 'selected':''}>1</option>
<option value="2" ${elem.quantity==2 ? 'selected':''}>2</option>
<option value="3" ${elem.quantity==3 ? 'selected':''}>3</option>
<option value="4" ${elem.quantity==4 ? 'selected':''}>4</option>
</select><br>
<button class="remove" onclick="delete_functionality(${i})">Remove</button>
</div>
<div class="item-data">
<p> ₹ ${elem.price * elem.quantity || elem.price} </p>
</div>
</div>
<div id="below-cart">
<p>No Cost EMI available</p>
<p>This item is eligible for No Cost EMI. Proceed to checkout to see how much you will save.</p>
</div>
<div id="item-total">
<p>Item total</p>
<p> ₹ ${elem.price * elem.quantity || elem.price}</p>
</div>
</div>
<div id="coupon-data">
<p id="coup">Coupon</p>
<input type="text" placeholder="Enter coupon" id="Discount">
<button id="cou" onclick="apply_coupon()">Apply Coupon</button>
<p id="agent"><span style="color:#006BBD";>Chat with an agent</span> or Call <span style="color:#006BBD";>1800-425-4002</span> for additional <br> help.</p>
<div style="border:1px solid #AAAAAA">
<div class="numitem">
<p>Discounted Amount</p>
<p>${elem.discount ? elem.discount : ""}</p>
</div>
<div class="numitem">
<p style="font-weight:700"; color:#444444;>Total Order Value</p>
<p style="font-weight:700"; color:#444444; >₹ ${ elem.price * elem.quantity - elem.discount || elem.quantity * elem.price}</p>
</div>
<p id="above">Above prices include Tax and Shipping</p>
<button id="check" id="checkout-admin"><a href="checkout.html">Checkout</a></button><br>
<button id="conti">Continue Shipping</button>
<div id="spanP">
<p >Save cart</p><span>|</span><p>Email your cart</p>
</div>
</div>
</div>
</div>
`
return card
}
function delete_functionality(i){
cart_data.splice(i,1)
console.log(cart_data)
// creating_card(cart_data)
display_list(cart_data)
localStorage.setItem("cart",JSON.stringify(cart_data))
}
function change_quantity(e,i){
cart_data[i].quantity=Number(e.target.value)
display_list(cart_data)
localStorage.setItem("cart",JSON.stringify(cart_data))
}
function apply_coupon(){
let discount=document.querySelector("#Discount").value
cart_data.forEach((element)=>{
element.discount=parseInt(discount)
})
display_list(cart_data)
localStorage.setItem("cart",JSON.stringify(cart_data))
}
let coupon_data = document.getElementById("coupon_data")
console.log(cart_data)
if(cart_data.length > 1){
coupon_data.innerHTML =""
}
</script>