-
Notifications
You must be signed in to change notification settings - Fork 0
/
addToCart.html
111 lines (86 loc) · 3.04 KB
/
addToCart.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add To Cart</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<a href="./index.html"></a>
<a href="./addToCart.html"></a>
<div style="display: flex;align-items: center;justify-content: center;">
<h1 style="text-align: center;color: #00b5b7;font-size: 50px;">
Add To Cart</h1>
<img style="width:5%;height:50px" src="https://tse4.mm.bing.net/th?id=OIP.fYPFuy5ypGwIotPEJMp_BAHaHa&pid=Api&P=0" id="add" />
</div>
<h1 id="total"><span style="padding-left: 30px;">
Your Total cart Price is:- </span><span id="cart-total">0</span></h1>
<div id="medicine-container">
</div>
</body>
</html>
<script>
let MedicineCart=JSON.parse(localStorage.getItem("medicine"))
let container=document.getElementById("medicine-container")
function displayData()
{
container.innerHTML=""
MedicineCart.forEach((medi) => {
let medicineContainer=document.createElement("div")
let category=document.createElement("h4")
category.className +="cate"
let rating=document.createElement("h5")
rating.className +="rating"
let discount=document.createElement("h5")
discount.className += "count"
let id=document.createElement("p")
let image=document.createElement("img")
let name=document.createElement("h3")
let price=document.createElement("h4")
let deleted=document.createElement("button")
let buy=document.createElement("button")
deleted.className+="del";
buy.className+="del"
category.innerText=medi.category;
rating.innerText=`${medi.rating} ★`;
id.innerText=medi.id;
image.src=medi.image;
name.innerText=medi.name;
price.innerText=`₹${medi.price}`;
deleted.innerText="Delete";
buy.innerText="Buy"
discount.innerText="Discount: "+`${medi.discount}%`
deleted.addEventListener("click",()=>
{
MedicineCart=MedicineCart.filter((ele)=>
{
return ele.id != medi.id
})
localStorage.setItem("medicine",JSON.stringify(MedicineCart))
displayData()
})
buy.onclick = function () {
location.href = "./payment.html";
}
let buying=[]
buy.addEventListener("click",()=>{
let bought=MedicineCart.filter((ele)=>
{
return ele.id == medi.id
})
buying.push({...bought[0]})
localStorage.setItem("selectedBoughtProduct",JSON.stringify(buying))
})
let sum=0;
for(let i=0;i<MedicineCart.length;i++){
sum+=MedicineCart[i].price
}
document.getElementById("cart-total").textContent=sum;
medicineContainer.append(image,rating,name,discount,price,category,deleted,buy)
container.append(medicineContainer)
});
}
displayData()
</script>