-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheckout_fitmeals.js
62 lines (42 loc) · 1.69 KB
/
checkout_fitmeals.js
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
var checkoutArr=JSON.parse(localStorage.getItem("CartItems"));
console.log(checkoutArr);
checkoutArr.map(function(data) {
var tr = document.createElement("tr");
// table data row created
// product description
var td1 = document.createElement("td");
// name of the product
var name = document.createElement("h4");
name.style.color = "#292d35"
td1.textContent = data.name;
var qty = document.createElement("h5");
qty.style.color = "rgb(91, 91, 91)";
qty.textContent = "Quantity : 500gm";
td1.append(name, qty);
// price of the product
var td2 = document.createElement("td");
td2.textContent = "₹" + data.price + ".00";
td2.setAttribute("class", "price")
tr.append(td1, td2);
//append
document.querySelector("tbody").append(tr);
});
var subtotal = checkoutArr.reduce(function(acc, cv) {
return acc + Number(cv.price);
},0);
localStorage.setItem("total", total);
document.querySelector("#subtotal").textContent = `₹${subtotal}.00`;
document.querySelector("#discount").textContent = `₹${Math.floor(subtotal/3.3)}.00`;
if(subtotal > 1) {
document.querySelector("#shipping").textContent = ` Flat rate : ₹${50}.00`;
}
document.querySelector("#total").textContent = `₹${(subtotal - Math.floor(subtotal/3.3)) + 50}.00`;
document.querySelector("#sbmt").addEventListener("click", formSubmit);
function formSubmit(event) {
window.location.href="orderplaced.html";
}
// document.getElementById("return").addEventListener("click", emptyCart);
function emptyCart() {
window.location.href = "home.html";
localStorage.removeItem("CartItems");
}