-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.js
146 lines (115 loc) · 4.8 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
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
var sum = 0;
let parent = document.getElementById("lists");
let product_des = document.getElementById("product_des");
let cart = JSON.parse(localStorage.getItem("cart"));
function showProducts() {
cart.forEach(function (product) {
cart.innerHTML = null;
let item_div = document.createElement("div");
let img = document.createElement("img");
img.src = product.img;
let product_price = document.createElement("p");
product_price.textContent = "$" + product.price;
let product_name = document.createElement("p");
product_name.textContent = product.name;
//console.log(product.name)
let removetocart_btn = document.createElement("button");
removetocart_btn.innerHTML = "Save for later";
// removetocart_btn.style.margin = "20px 6px";
removetocart_btn.addEventListener("click", removeItem);
function removeItem() {
parent.style.display = none;
}
item_div.append(img, product_price, removetocart_btn);
let prod_des_para = document.createElement("p");
let Expected_devivery = document.createElement("p");
Expected_devivery.innerText = "Expected devivery";
let devivery = document.createElement("P");
devivery.innerText = " Wed Oct 6 - Fri Oct 15";
let product_des = document.createElement("div");
prod_des_para.textContent = product.name;
let devivery_details = document.createElement("div");
devivery_details.append(Expected_devivery, devivery);
product_des.append(prod_des_para, devivery_details);
parent.append(item_div, product_des);
// prod_des_para.append(product_name);
// product_des.append(prod_des_para);
sum = sum + Number(product.price);
});
// console.log(sum);
// console.log(cart.length);
// if(coupn.value == "WELCOMETOKOLI50"){
// total_amount = total_amount * (50 / 100);
// }
let total_items = cart.length;
let total_amount = sum + 10 + 8;
// let final_value = total_amount;
// let amount = document.getElementById("amount");
// let list = document.getElementById("list")
let d1 = document.getElementById("d1");
let d2 = document.getElementById("d2");
let d3 = document.getElementById("d3");
// let coupn = document.createElement("input");
// let line = document.createElement("hr")
let d4 = document.getElementById("d4");
let checkout_valu = document.getElementById("checkout_valu");
let coupn;
// let total = document.createElement("p")
// l2.textContent = sum;
d1.textContent = total_items;
d2.textContent = "$10";
d3.textContent = "$8";
d4.textContent = "$" + total_amount;
checkout_valu.textContent = " " + "$" + total_amount;
checkout_valu.style.color = "#FFF176";
// coupn.value = null;
// if(coupn.value == "WELCOMETOKOLI50"){
// final_value = total_amount * (50 / 100);
// }else{
// final_value = total_amount;
// }
// function checkCouponCopde(){
// if(coupn.value == "WELCOMETOKOLI50"){
// alert("Coupon Applied sucessfully")
// }else{
// alert("Invallied Coupon code")
// }
// }
function removetoCart(product) {
alert("remove");
}
// check & apply promocode
// list.append(l1,l2,l3,coupn,line,l5);
// parent.append("list");
}
function checkcode() {
// alert("check code")
let code = document.getElementById("promocode").value;
if (code == "WEL60") {
alert("Coupon Applied sucessfully");
let cart = JSON.parse(localStorage.getItem("cart"));
sum = 0;
cart.forEach(function (product) {
sum = sum + Number(product.price);
});
var mainsum = (sum * (60 / 100)).toFixed(2);
dis = (sum - mainsum).toFixed(2);
// console.log(mainsum)
// console.log(dis) //pay after discount <--- this is after discount price
let promo_btn = document.getElementById("promo_btn");
promo_btn.innerText = "Applied";
let checkout_valu = document.getElementById("checkout_valu");
checkout_valu.textContent = " " + "$" + mainsum;
d4.textContent = mainsum;
let discount = document.getElementById("discount");
discount.textContent = " " + "$" + dis;
discount.style.color = "#00796B"
let your_saving = document.getElementById("your_saving");
your_saving.style.color = "#00796B"
} else if (code == "") {
alert("You have'nt apply any code");
} else {
alert("Invalid Coupon code Please Check Carefully");
}
}
showProducts();