-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.js
108 lines (93 loc) · 3.43 KB
/
cart.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
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
var cart = JSON.parse(localStorage.getItem("datas"));
showProducts(cart);
function showProducts(event) {
document.getElementById("images").innerHTML = "";
event.map(function (item) {
var imgs = document.createElement("img");
imgs.setAttribute("src", item.image_url);
imgs.setAttribute("id", "imageSizing");
var type = document.createElement("p");
type.textContent = item.type;
type.setAttribute("class", "paraStyle");
var description = document.createElement("p");
description.textContent = item.dsc;
description.setAttribute("class", "paraStyle1");
var x = document.createElement("div");
x.setAttribute("id", "x");
var price = document.createElement("span");
price.textContent = "$" + item.MRP;
price.setAttribute("class", "pricing");
var disc = document.createElement("span");
disc.textContent = "$" + item.discount;
disc.setAttribute("id", "discStyle");
var discPer = document.createElement("span");
discPer.textContent = item.discountPercentage + "% OFF";
discPer.setAttribute("id", "discPerStyle");
x.append(price, disc, discPer);
var imgDiv = document.createElement("div");
imgDiv.setAttribute("id", "img");
var btn = document.createElement("button");
btn.setAttribute("class", "btnremove");
btn.textContent = "Remove";
btn.addEventListener("click", function () {
remove(item);
});
imgDiv.append(imgs, type, description, x, btn);
document.getElementById("images").append(imgDiv);
// imgDiv.append(x);
});
}
var total = cart.reduce(function (acc, c) {
return acc + Number(c.MRP);
}, 0);
console.log(total);
document.querySelector(
".details"
).innerHTML = `<h4 class="ordersum">Summary</h4><table class="cartsec">
<tr><td>Subtotal</td>
<td>$${Math.floor(total)}</td>
</tr>
<tr>
<td>Delievery</td>
<td><span class="underline">$100</span><span class="free"></span></td></tr>
<tr><td class="line">ORDER TOTAL</td>
<td class="line">$${Math.floor(total)}</td></tr></table>
<p class="text">Order in time for 25 December Find final shipping dates plus extended returns info here</p>
<button class="btnc">Go To Checkout > </button>`;
//console.log(cart)
function remove(item) {
cart.splice(cart.indexOf(item), 1);
localStorage.setItem("datas", JSON.stringify(cart));
window.location.reload(true);
}
document.querySelector("#apply").addEventListener("click", discount);
function discount() {
var dis = document.querySelector("#val").value;
if (dis == "masai30") {
document.querySelector(
".details"
).innerHTML = `<h4 class="ordersum">ORDER SUMMARY</h4><table class="cartsec">
<tr><td>Order value</td>
<td>₹${total}</td>
</tr>
<tr>
<td>Shipping</td>
<td><span class="underline">₹100 </span><span class="free">Free</span></td></tr>
<tr><td class="line">ORDER TOTAL</td>
<td class="line">₹${Math.floor(
total - (total / 100) * 30
)}</td></tr></table>
<p class="you">YOU HAVE SAVED 30% ON THIS ORDER</p>
<p class="text">90 DAYS RETURN EXCLUSIVELY FOR GREENCARD MEMBER</p>
<button class="btnc">continue</button>`;
} else {
alert("Not vaild Coupon Code");
}
document.querySelector("#val").value = "";
document.querySelector(".btnc").addEventListener("click", function () {
window.location.href = "address.html";
});
}
document.querySelector(".btnc").addEventListener("click", function () {
window.location.href = "address.html";
});