-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBags&Walletsproducts.js
122 lines (98 loc) · 3.07 KB
/
Bags&Walletsproducts.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
let container = document.getElementById("Products-container");
let h2 = document.querySelector("h2");
let y = JSON.parse(localStorage.getItem("products"))||[]
let x = y[y.length-1]
h2.innerText = x;
console.log(x)
let bag = "";
for(let i=0;i<x.length;i++){
if(x[i]==" "){
bag+="-";
}
else{
bag+=x[i];
}
}
console.log(bag)
fetch(`http://127.0.0.1:9090/${bag}`)
.then((res)=>{
return res.json();
})
.then((res)=>{
display(res)
})
function display(data){
data.forEach((element) => {
let card = document.createElement("div");
let img = document.createElement("img");
let name = document.createElement("p");
let pricediv = document.createElement("div")
let price = document.createElement("span");
priceRemove = document.createElement("span");
priceRemove.textContent = element.price+850;
price.textContent = `Rs.${element.price}`;
priceRemove.setAttribute("class","span1")
price.setAttribute("class","span2")
pricediv.setAttribute("class","pricediv")
if(element.thumbnail ===""){
img.src = element.image[0];
}
else{
img.src = element.thumbnail;
}
name.textContent = element.title;
price.textContent = `Rs.${element.price}`;
pricediv.append(price,priceRemove)
container.append(card);
card.append(img,name,pricediv)
card.addEventListener("click",()=>{
let obj = {}
obj.name = element.title;
obj.img = element.thumbnail;
obj.price = element.price;
obj.images = element.images;
obj.id = element.id;
let arr =[];
let recentArr = JSON.parse(localStorage.getItem("recently-viewed"))||[];
if(recentArr.length===12){
recentArr.shift();
}
recentArr.push(obj);
arr.push(obj);
localStorage.setItem("single-data",JSON.stringify(arr))
localStorage.setItem("recently-viewed",JSON.stringify(recentArr))
window.location.href = "./single-product-page.html"
})
});
}
let logo = document.getElementById("logo")
logo.addEventListener("click",()=>{
window.location.href="./index.html"
})
let cartcount = document.querySelector(".cartcount");
let cartdata = JSON.parse(localStorage.getItem("cartdata")) || [];
if (cartdata.length === 0) {
cartcount.style.display = "none"
}
cartcount.innerText = cartdata.length;
fetch(`http://127.0.0.1:9090/CHARGING-SOLUTIONS-CATEGORY`)
.then((res) => {
return res.json();
})
.then((res) => {
let filterdata=res[`${bag}`];
console.log(filterdata)
displaycategory(filterdata)
})
let filterEl = document.querySelector("#filter-div");
function displaycategory(data){
data.forEach((element)=>{
let filterCard = document.createElement("div");
let image = document.createElement("img");
image.src = element.image;
let name = document.createElement("p");
name.textContent = element.name;
filterCard.append(image,name)
filterEl.append(filterCard)
})
}