forked from Abhinav068/Beautify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProduct_detail.js
129 lines (109 loc) · 4.03 KB
/
Product_detail.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
import { dropmenu, navbar } from "./exoportNavBar.js";
import { footer } from "./footer.js";
document.querySelector("nav").innerHTML = navbar()
document.getElementById("drop").innerHTML = dropmenu()
document.getElementById("bottom-footer").innerHTML = footer()
let user = localStorage.getItem("username") || ""
let status = localStorage.getItem("status")
if(status == "true"){
document.getElementById("signin").innerText = user
}
document.querySelector("#Back").addEventListener("click", () => {
window.location.href = "product.html";
})
let Product_url = "https://636b3a947f47ef51e12abb5f.mockapi.io/product_data";
let id = JSON.parse(localStorage.getItem("product_id"));
fetch(Product_url).then(data => (data.json())).then(res => {
for (const item of res) {
if (id == item.id) {
dislpay(item);
}
}
});
let cart_item = JSON.parse(localStorage.getItem("cart_item")) || [];
let wish_item = JSON.parse(localStorage.getItem("wish_item")) || [];
function dislpay(item) {
let div = document.createElement("div");
for (const image of item.image) {
let photo = document.createElement("img");
photo.src = image;
div.append(photo);
}
document.querySelector("#card1").append(div);
let title = document.createElement("h2");
title.innerText = item.name;
let Price = document.createElement("h3");
Price.innerHTML = `
<p style="color:silver">Inclusive of All Taxes</p>
<p>Price : ₹ ${item.price}</p>`;
let rating = document.createElement("h4");
rating.innerHTML = `<p>Rating : ${item.rating}</p>`;
let category = document.createElement("h4");
category.innerHTML = `<p>Category : ${item.category}</p>`;
let descript = document.createElement("p");
descript.innerText = item.des;
let button_box = document.createElement("div");
button_box.setAttribute("id", "button_box")
let cart_btn = document.createElement("button");
cart_btn.innerText = "Add to Bag";
cart_btn.addEventListener("click", () => {
cart_btn.style.backgroundColor = "green";
let check = false;
for (let i = 0; i < cart_item.length; i++) {
if (item.id == cart_item[i].id) {
check = true;
break;
}
}
if (check == false) {
cart_item.push(item);
localStorage.setItem("cart_item", JSON.stringify(cart_item))
alert("Item added Successfully");
} else {
alert("Item already in the Bag");
}
})
let buy_btn = document.createElement("button");
buy_btn.innerText = "Buy Now";
buy_btn.addEventListener("click", () => {
if(status == "true"){
localStorage.setItem("Price",item.price)
window.location.href = "./Credit card payment/payment.html.html";
}
else{
alert("Please Login")
window.location.href = "login.html"
}
})
let wishlist_btn = document.createElement("button");
wishlist_btn.innerText = "Add to Wishlist";
wishlist_btn.addEventListener("click", () => {
wishlist_btn.style.backgroundColor = "green";
let check = false;
for (let i = 0; i < wish_item.length; i++) {
if (item == wish_item[i]) {
check = true;
break;
}
}
if (check == false) {
wish_item.push(item);
localStorage.setItem("wish_item", JSON.stringify(wish_item))
alert("Item added Successfully");
} else {
alert("Item already in the Wishlist");
}
})
button_box.append(cart_btn, buy_btn, wishlist_btn);
document.querySelector("#card2-top").append(title, Price, rating, category, descript, button_box);
}
document.querySelector("#signin").addEventListener("click",function log(){
if(status == "true"){
localStorage.setItem("status",false)
document.getElementById("signin").innerText = "Sign in"
location.reload()
}
else{
window.location.href = "login.html"
}
})