-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheckout.js
More file actions
56 lines (53 loc) · 1.78 KB
/
Copy pathcheckout.js
File metadata and controls
56 lines (53 loc) · 1.78 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
let count = 0;
const addressModal = () => {
count++;
if(count%2==1) {
document.querySelector('.selectDeliveryAddress').style.display = "block"
} else {
document.querySelector('.selectDeliveryAddress').style.display = "none"
}
}
const goToHome = () => {
window.location.href ="index.html"
}
const queryFun = () => {
let query = window.location.search;
let id = new URLSearchParams(query)
return id
}
const loadCartData = () => {
let id = queryFun()
url = `https://decathlon-mock.herokuapp.com/cart`
console.log(url)
fetch(url).then((data) => data.json()).then((data) => createCart(data))
}
const createCart = (data) => {
let totalAmt = 0;
let deliveryChg = 0
for(i in data){
totalAmt += data[i].current_price * data[i].qty;
let deliveryChg = 129;
if (totalAmt>=1000){
deliveryChg = 0;
document.querySelector('.shipping').innerHTML = `<p>SHIPPING</p>
<p>FREE</p>`
}else{
document.querySelector('.shipping').innerHTML = `<p>Estimated delivery</p>
<p>₹ 129</p>`
}
console.log(data[i])
if(data.length == 1){
document.querySelector('.itemImg').innerHTML= `<img src="${data[i].img}"/>`
document.querySelector('.orderItemName').textContent = data[i].name
document.querySelector('.itemOrderDetail').innerHTML = `
<p>Size:<strong>${data[i].size.toUpperCase()}</strong></p>
<p>Quantity:<strong>${data[i].qty}</strong></p>
<p><strong>₹${totalAmt}</strong></p>
`
}else{
document.querySelector('.items').style.display = 'none';
}
}
document.querySelector('.total').textContent = "₹ " +(totalAmt + deliveryChg);
}
window.addEventListener('load', loadCartData)