-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddToCart.js
119 lines (101 loc) · 3.49 KB
/
AddToCart.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
109
110
111
112
113
114
115
116
let loginDet=JSON.parse(localStorage.getItem("userDet"))||[]
console.log(loginDet)
let cartData = JSON.parse(localStorage.getItem("kids-NewArr"))||[]
DisplayData(cartData)
function DisplayData(cartData) {
document.querySelector("#cart").innerHTML = null;
cartData.forEach(function (ele) {
let DIV = document.createElement("div");
let DIV3 = document.createElement("div");
let DIV4 = document.createElement("div");
let DIV1 = document.createElement("div");
let DIV2 = document.createElement("div");
let Image = document.createElement("img");
Image.src = ele.img
let Name = document.createElement("p");
Name.innerText = ele.name;
Name.id = "ProductName";
let Remove = document.createElement("p");
Remove.innerText = "X-Remove";
Remove.id = "RemovERow";
Remove.addEventListener("click", function () {
DeleteRow(ele)
})
let price = document.createElement("p");
price.innerText = "€" + " " + ele.price;
let qty = document.createElement("input");
qty.value = ele.qty;
qty.setAttribute.id = "UpdateQty";
qty.style.textAlign = "center"
// console.log(qty.value)
qty.addEventListener("change", function () {
GetQuantityChangeS(ele, qty);
})
let subTotal = document.createElement("p");
subTotal.innerText = "€" + " " + (ele.price) * (qty.value);
let line = document.createElement("hr")
DIV1.append(Image);
DIV2.append(Name, Remove); //ele.qty
DIV3.append(DIV1, DIV2);
DIV4.append(price, qty, subTotal)
DIV.append(DIV3, DIV4);
document.querySelector("#cart").append(DIV, line)
console.log(DIV1, DIV2, DIV3, DIV4, DIV)
})
}
function DeleteRow(ele) {
let Name = ele.name;
cartData = cartData.filter(function (element) {
return element.name != Name;
})
localStorage.setItem("kids-NewArr", JSON.stringify(cartData));
DisplayData(cartData)
}
function GetQuantityChangeS(ele, qty) {
let x = qty.value;
console.log(x)
ele.qty = x;
// console.log(x);
localStorage.setItem("kids-NewArr", JSON.stringify(cartData));
DisplayData(cartData)
DisplayTotalPrice();
}
DisplayTotalPrice();
function DisplayTotalPrice() {
let ResultantTotal = cartData.reduce(function (Sum, ele) {
return Sum + ((ele.price) * (ele.qty))
}, 0)
// console.log(ResultantTotal)
document.querySelector("#subTotal").innerText = ResultantTotal;
document.querySelector("#grandTotal").innerText = ResultantTotal;
}
let form = document.querySelector("#form");
document.querySelector("#form").addEventListener("submit", PromoCode);
let count = 0;
function PromoCode(event) {
event.preventDefault();
let old = document.querySelector("#grandTotal").innerText;
let code = (form.wcode.value);
if (code == "Rocking$200" && count == 0) {
old = (old * 80) / 100;
alert("PromoCode Applied Successfully");
count = 1;
document.querySelector("#grandTotal").innerText = old;
}
else if (count === 1) {
alert("PromoCode Already Applied");
}
else {
alert("Invalid PromoCode");
}
}
function MainPage() {
window.location.href = "NEW ARRIVAL3.html"
}
function Forward(loginDet) {
if(loginDet.length===1){
window.location.href = "Delivery.html"
}else{
alert("You Are Trying to Cheat.Please login first");
}
}