-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcart.html
More file actions
352 lines (318 loc) · 11.9 KB
/
cart.html
File metadata and controls
352 lines (318 loc) · 11.9 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<script src="/js/auth.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-163674715-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-163674715-1');
</script>
<!-- Required meta tags -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" />
<link rel="stylesheet" href="./css/style.css" />
<script src="https://kit.fontawesome.com/a166c5af45.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css"
integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title>Cart</title>
<link rel="icon" href="./assets/images/collegeshala-logo-svg.svg" />
<script src="./js/cart.js" async></script>
</head>
<body onload="fetchData()">
<nav class="navbar custom-nav navbar-expand-lg navbar-light bg-custom-blur">
<a class="navbar-brand" href="/">
<img src="./assets/images/logo.png" id="logo" alt="" />
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText"
aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<p class="nav-seach-box">
<input type="text" id="search-input" placeholder="Search your subject here " />
</p>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link navbar-talkshala" href="./coming-soon.html">
TalkShala
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/cart.html">
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./my-account.html">
<i class="fa fa-user-circle" aria-hidden="true"></i>
</a>
</li>
</ul>
</div>
</nav>
<div class="container pt-4">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-item"><a href="#">User Name</a></li>
<li class="breadcrumb-item active" aria-current="page">Cart</li>
</ol>
</nav>
</div>
<div class="container cart">
<!-- notes go here -->
</div>
</div>
<div class="container total-cart">
<div id="box">
<h5 class="cart-total-heading">Total price of the Cart</h5>
<h1 class="cart-total-amount" id="custom-purple"><span>0</span><span> credits</span></h1>
<button href="#" class="checkout-btn-cart" id="custom-red">Checkout</button>
</div>
</div>
<!-- Site footer -->
<footer class="site-footer">
<div class="container">
<div class="row">
<div class="col-12 col-md-6">
<!--<h6>About the company</h6> -->
<a href="./about.html">
<h6 class="text-justify">
About Us
</h6>
</a>
<div class="row">
<div class="col-12 col-md-4">
<a target="_blank" href="./copyright.html">Copyright</a><br />
<a target="_blank" href="./disclaimer-warranties.html">Disclaimer Warranties</a><br />
<a target="_blank" href="./privacy-policy.html">Privacy Policy</a>
</div>
<div class="col-12 col-md-4">
<a target="_blank" href="./return-policy.html">Return Policy</a><br />
<a target="_blank" href="./professor-info.html">Course Advisors</a><br />
<a target="_blank" href="./terms-of-use.html">Terms of Use</a>
</div>
</div>
</div>
<!--
<div class="col-xs-6 col-md-3">
<h6>Important Links</h6>
<ul class="footer-links">
<li>
<a href="">lorem Ipsum</a>
</li>
<li>
<a href="">lorem Ipsum</a>
</li>
<li>
<a href="">lorem Ipsum</a>
</li>
<li>
<a href="http://scanfcode.com/category/java-programming-language/">Lorem Ispum</a>
</li>
</ul>
</div>
-->
<div class="col-xs-6 col-md-4">
<h6>Connect With Us</h6>
<ul class="footer-links">
<li>
<a target="_blank" href=""><img src="./assets/images/footer/twitter-icon.png" id="footer-social-icons"
alt="" srcset="" /></a>
<a target="_blank" href="mailto:collegeshala2020@gmail.com"><img
src="./assets/images/footer/gmailicon.png" id="footer-social-icons" alt="" srcset="" /></a>
<a target="_blank" href="https://www.facebook.com/CollegeShalareal/"><img
src="./assets/images/footer/facebook-icon.png" id="footer-social-icons" alt="" rcset="" /></a>
<a target="_blank" href="https://www.linkedin.com/company/collegeshala-edutech/"><img
src="./assets/images/footer/linkedin-icon.png" id="footer-social-icons" alt="" rcset="" /></a>
</li>
<li>
<a target="_blank"
href="https://www.google.com/maps/dir//offbeats+ccu/data=!4m6!4m5!1m1!4e2!1m2!1m1!1s0x3a02772f380eb913:0xbc0dddd2e9b59b53?sa=X&ved=2ahUKEwj14s2a3I_pAhUGwzgGHW2kAe0Q9RcwDXoECB0QDg">Office:
405, OFFBEAT CCU, 36/F, Topsia Rd, Topsia, Kolkata,
West Bengal 700039</a>
</li>
<li>
<a href="#">Call US: 8583994561, 9230429404</a>
</li>
</ul>
</div>
</div>
</div>
<div class="copyright-area">
<p class="text-center" id="footer-copyright-text">
<i class="far fa-copyright"></i> 2020 CollegeShala | All Rights
Reserved
</p>
</div>
</footer>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="./js/scroll.js"></script>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script src="/js/razorpay.js"></script>
<script src="./js/auth.js"></script>
<script>
let token = window.localStorage.getItem("idToken");
let state = {
total: 0,
cart: []
}
$(".checkout-btn-cart").click(async function () {
function checkoutRes() {
return new Promise(function (resolve, reject) {
$.ajax({
method: 'POST',
url: "https://api.collegeshala.com/checkout",
headers: {
authorization: token,
},
data: JSON.stringify({}),
contentType: 'application/json',
success: function complete(result) {
// console.log(result);
resolve(result);
},
error: function error(err) {
console.error(err);
reject(err);
}
});
});
}
let resp = await checkoutRes();
console.log(resp);
if (resp.msg && resp.msg == "Insufficient credits") {
console.log("insufficient")
let creditsBalance = state.total - resp.creditsAvailable;
let amt = creditsBalance * 10 * 100;
checkout(amt, creditsBalance, token);
// window.location.reload();
} else {
alert("Notes purchased successfully!");
window.location.href = "/student-dashboard.html";
}
})
async function fetchData() {
function getCart() {
return new Promise(function (resolve, reject) {
$.ajax({
method: 'POST',
url: "https://api.collegeshala.com/fetchcart",
headers: {
authorization: token,
},
data: JSON.stringify({}),
contentType: 'application/json',
success: function complete(result) {
resolve(result);
},
error: function error(err) {
reject(err)
}
});
})
}
let resp = await getCart();
// state.cart = resp.Responses.notes;
state.cart = resp.Responses.notes.map(note => {
let parsed_note = {};
for (x in note) {
parsed_note[x] = note[x].S || (note[x].N * 1) || note[x].BOOL;
}
return parsed_note;
});
// console.log(state.cart);
state.total = 0;
for (note of state.cart) {
state.total += note.requiredCredits;
}
// console.log(state.total)
setData();
}
function setData() {
state.cart.forEach(note => {
$(".cart").append(
`<div class="row notes-info-tab" id="${note.noteId}">
<a href="">
<div class="col-12 col-md-2"><img width="85" height="85" src="./assets/images/pdf_logo.svg"
class="all-prod-img rounded float-left" alt="..."></div>
</a>
<div class="col-12 col-md-8">
<a href="">
<h5>
<span id="custom-purple">${note.chaptername} </span> - ${note.subjectname}
</h5>
</a>
<div class="row">
<div class="col-12 col-md-4"><a href="">
<h5><i class="fas fa-user-circle"></i>${note.professorname}</h5>
</a></div>
<div class="col-12 col-md-4">
<h5><i class="fas fa-graduation-cap"></i>${note.universityname}</h5>
</div>
<div class="col-12 col-md-4">
<h4>₹ ${note.requiredCredits * 10}</h4>
</div>
</div>
</div>
<div class="col-12 col-md-2 mt-3">
<button type="button" value="${note.noteId}" class="btn btn-danger">Remove</button>
</div>
</div>`
)
});
$(".cart-total-amount").text(`${state.total} credits`);
deleteNote();
}
</script>
<script>
$("#search-input").change(function () {
localStorage.setItem("value", event.target.value);
window.location.pathname = "/all-product.html";
});
function deleteNote() {
$(".btn-danger").click(function () {
event.preventDefault();
const noteid = event.target.value;
console.log(noteid);
$.ajax({
method: 'POST',
url: "https://api.collegeshala.com/remove-note-from-cart",
headers: {
authorization: token,
},
data: JSON.stringify({
noteId: noteid
}),
contentType: 'application/json',
success: function complete(result) {
state.total -= 2;
$(`#${noteid}`).remove();
$(".cart-total-amount").text(`${state.total} credits`);
},
error: function error(err) {
console.error(err);
}
});
});
}
</script>
</body>
</html>