forked from BASHISTHANAYAK/WEB101_PROJECT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfragrance.js
208 lines (199 loc) · 6.94 KB
/
fragrance.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
let products = [
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/s/8/s8.jpg",
name:"Calvin Klein Eternity For Men Eau De Parfum",
price:"₹3,468.00",
price1:3468,
productID: "women1",
nwearrival:1,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo21.jpg",
name:"Fogg Bleu Series Island Fragrance Body Spray",
price:"₹255.00",
price1:255,
productID: "women2",
nwearrival:0,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo20.jpg",
name:"Fogg Force Fragrance Body Spray",
price:"₹230.00",
price1:230,
productID: "women3",
nwearrival:0,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo19.jpg",
name:"Fogg Punch Fragrance Body Spray",
price:"₹230.00",
price1:230,
productID: "women4",
nwearrival:1,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo18.jpg",
name:"Fogg Bleu Series Mountain Fragrance Body Spray",
price:"₹255.00",
price1:255,
productID: "women5",
nwearrival:1,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo17.jpg",
name:"Fogg Rush Fragrance Body Spray",
price:"₹230.00",
price1:230,
productID: "women6",
nwearrival:0,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo16.jpg",
name:"Fogg Bleu Skies Fragrance Body Spray",
price:"₹275.00",
price1:275,
productID: "women7",
nwearrival:1
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo15.jpg",
name:"Fogg Scent Intensio Men Fragrance Body Spray",
price:"₹539.00",
price1:539,
productID: "women8",
nwearrival:0,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo13.jpg",
name:"Fogg Master Cedar Body Spray",
price:"₹275.00",
price1:275,
productID: "women9",
nwearrival:0,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo12.jpg",
name:"Fogg Black Fresh Aromatic Fragrance Body Spray",
price:"₹250.00",
price1:250,
productID: "women10",
nwearrival:1,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo10.jpg",
name:"Fogg Master Agar Body Spray",
price:"₹275.00",
price1:275,
productID: "women11",
nwearrival:0,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo9.jpg",
name:"Fogg Black Fresh Fougere Body Spray Deodorant For",
price:"₹250.00",
price1:250,
productID: "women12",
nwearrival:1,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo8.jpg",
name:"Fogg Scent Xpressio Men Fragrance Body Spray",
price:"₹539.00",
price1:539,
productID: "women13",
nwearrival:1,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo7.jpg",
name:"Fogg Dynamic Fragrance Body Spray",
price:"₹250.00",
price1:250,
productID: "women14",
nwearrival:0,
},
{
img:"https://www.beautybebo.com/pub/media/catalog/product/cache/37253e89591b79b38c00254331932999/f/o/fo6.jpg",
name:"Fogg Scent Xtremo Men Fragrance Body Spray",
price:"₹539.00",
price1:539,
productID: "women15",
nwearrival:1,
},
];
let ProductCont = document.querySelector('.products');
let cartLS=JSON.parse(localStorage.getItem("cart-page")) || [];
function displayProducts(data){
ProductCont.innerHTML="";
data.forEach(function (element){
let Product = document.createElement("div");
let img = document.createElement('img');
img.src = element.img;
let name = document.createElement('p');
name.innerText = element.name;
let price = document.createElement('p');
price.innerText = element.price;
let buttonCart = document.createElement('button');
buttonCart.innerHTML = ' <i class="fa-solid fa-basket-shopping"></i> Add to Cart';
buttonCart.addEventListener("click",function(){
if( addToCartfunc(element.productID)===true){
alert("Product Added Successfully");
cartLS.push(element);
localStorage.setItem("cart-page",JSON.stringify(cartLS));
}else{
alert("product Already in the cart");
}
})
let wishlist = document.createElement('button');
wishlist.innerHTML = '<i class="fa-solid fa-heart"></i>';
Product.append(img,name,price,buttonCart,wishlist)
ProductCont.append(Product)
});
}
displayProducts(products);
function addToCartfunc(id){
for(i=0;i<cartLS.length;i++){
if(cartLS[i].productID ==id){
return false;
}
}
return true;
}
let catalog =document.getElementsByClassName('contentBox');
for (i = 0;i < catalog.length; i++ ){
catalog[i].addEventListener("click", function(){
this.classList.toggle('active')
})
}
let filter = document.getElementById("filter");
filter.addEventListener("change",function(){
if(filter.value === "position"){
displayProducts(products);
window.location.reload(true);
}else if (filter.value === "NewArrival"){
let filtered = products.filter(function(element){
return element.nwearrival===1;
})
displayProducts(filtered);
}else if (filter.value === "LowToHigh"){
let priceLH = products.sort(function(a,b){
if(a.price1 > b.price1) return 1
if(a.price1 < b.price1) return -1
return 0
})
displayProducts(priceLH);
}else if (filter.value === "HighToLow"){
let priceHL = products.sort(function(a,b){
if(a.price1 > b.price1) return -1
if(a.price1 < b.price1) return 1
return 0
})
displayProducts(priceHL);
}else if (filter.value === "Name"){
let nameP = products.sort(function(a,b){
if(a.name > b.name) return 1
if(a.name < b.name) return -1
return 0
})
displayProducts(nameP);
}
})