-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackagedetails.js
161 lines (130 loc) · 4.96 KB
/
packagedetails.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
import { topHeader, searchBox, links } from "../components/header/navbar.js";
import footer from "../components/footer/footer.js";
// Navbar Import section
document.querySelector(".header-sec-1").innerHTML = await topHeader();
document.querySelector(".search-box").innerHTML = await searchBox();
document.querySelector(".footer").innerHTML = await footer();
let packageitem = JSON.parse(localStorage.getItem("order_details"));
let package_details = document.getElementById("package-details");
// Cart Details
let cart_count = 0;
let old_cart;
if (localStorage.getItem("cart") == null) {
old_cart = [];
localStorage.setItem("cart", JSON.stringify(old_cart));
} else {
old_cart = JSON.parse(localStorage.getItem("cart"));
}
update_cart_count();
function update_cart_count() {
if (localStorage.getItem("cart-count") == null) {
document.getElementById("cart_count").innerHTML = ` 0 Item`;
} else {
cart_count = localStorage.getItem("cart-count");
console.log(cart_count);
document.getElementById("cart_count").innerHTML = `${cart_count} Item`;
document.getElementById("cart-icon").innerHTML = `${cart_count}`;
}
}
displaypackage();
function displaypackage() {
let item = document.createElement("div");
item.className = "item";
let item_heading = document.createElement("div");
item_heading.className = "itemHeading";
let h4 = document.createElement("h4");
h4.textContent = packageitem.title;
document.title = `${packageitem.title}`;
let test_includes = document.createElement("div");
test_includes.className = "testIncludes";
test_includes.textContent = "Includes " + packageitem.testInclude + " tests";
item_heading.append(h4, test_includes);
let item_price = document.createElement("div");
item_price.className = "itemPrice";
let price = document.createElement("p");
price.className = "price";
price.textContent = "₹" + packageitem.price;
let actual_price = document.createElement("p");
actual_price.className = "actualPrice";
let actual_price_strike = document.createElement("strike");
actual_price_strike.textContent = " " + "₹" + packageitem.actualPrice;
//add to cart
let add_to_cart = document.createElement("h2");
add_to_cart.className = "add-to-cart";
let go_to_cart = document.createElement("h2");
go_to_cart.className = "go-to-cart";
go_to_cart.textContent = "ADDED GO TO CART";
if (checkAvailableInCart(packageitem.title)) {
// add_to_cart.textContent = "ALREADY ADDED TO THE CART";
go_to_cart.style.display = "block";
go_to_cart.addEventListener("click", function () {
location.href = "./cart.html";
});
} else {
add_to_cart.textContent = "ADD TO CART";
add_to_cart.addEventListener("click", function () {
cart_count++;
localStorage.setItem("cart-count", JSON.stringify(cart_count));
update_cart_count();
old_cart.push(packageitem);
localStorage.setItem("cart", JSON.stringify(old_cart));
go_to_cart.style.display = "block";
add_to_cart.style.display = "none";
go_to_cart.addEventListener("click", function () {
location.href = "./cart.html";
});
});
}
// Adding Add to cart function
// }else if(checkAvailableInCart==true){
// go_to_cart.style.display='block';
// add_to_cart.style.display='none';
// }else{
// add_to_cart.style.display='block';
// go_to_cart.style.display='none';
// }
// go_to_cart.addEventListener('click',function(){
// window.open('cart.html','_blank');
// });
let overview_heading = document.createElement("h2");
overview_heading.className = "overview-heading";
overview_heading.textContent = "Overview of " + packageitem.title;
let overview_detail = document.createElement("div");
let overview_detail_heading = document.createElement("h2");
overview_detail_heading.className = "overview-detail-heading";
overview_detail_heading.textContent =
"How " + packageitem.title + " helps you?";
let overview_p = document.createElement("p");
overview_p.className = "overview_p";
overview_p.textContent = packageitem.discription;
overview_detail.append(overview_detail_heading, overview_p);
actual_price.append(actual_price_strike);
item_price.append(actual_price, price);
let discount = document.createElement("div");
discount.className = "discount";
discount.textContent = packageitem.discount + "% off";
item.append(item_heading, item_price, discount, add_to_cart, go_to_cart);
package_details.append(item, overview_heading, overview_detail);
}
function checkAvailableInCart(title) {
let flag = false;
let cart = JSON.parse(localStorage.getItem("cart"));
cart.forEach(function (ele) {
if (title == ele.title) {
flag = true;
}
});
return flag;
}
// function addingCart() {
// let cart = localStorage.getItem("cart");
// if (cart == null) {
// localStorage.setItem("cart", JSON.stringify(package_details));
// } else {
// let oldcart = localStorage.getItem(JSON.stringify("cart"));
// oldcart.push(package_details);
// localStorage.setItem("cart", JSON.stringify(oldcart));
// }
// }
// console.log(packageitem.title);
localStorage.removeItem("order_details");