-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathViewSelected.js
89 lines (73 loc) · 3.12 KB
/
ViewSelected.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
import { navbar } from "./navbar.js";
document.getElementById("navbar").innerHTML = navbar();
import {footer} from "./footer.js";
document.getElementById('btmnavbar').innerHTML = footer();
let SelectedItem = JSON.parse(localStorage.getItem("Selected"));
let FirstPic = document.createElement("img");
FirstPic.src = SelectedItem.image[0].dataAltImage;
let secondPic = document.createElement("img");
secondPic.src = SelectedItem.image[0].src;
document.querySelector("#TwoImage").append(secondPic, FirstPic);
let title = document.createElement("h4");
title.innerText = SelectedItem.title;
let brand = document.createElement("p");
brand.setAttribute("id", "brand");
brand.innerText = SelectedItem.brandName;
let category = document.createElement("p");
category.setAttribute("id", "brand");
category.innerText = SelectedItem.category;
let price = document.createElement("h5");
price.setAttribute("id", "price");
price.innerText = SelectedItem.price;
document.querySelector("#DetailDiv").append(title, brand, category, price);
let size = document.createElement("p");
size.setAttribute("id", "brand");
size.innerText = SelectedItem.promotionalMarkerText;
document.querySelector("#size").append(size);
for (let i = 0; i < SelectedItem.swatches.length; i++) {
let firstcolor = document.createElement("option");
firstcolor.innerText = SelectedItem.swatches[i].colorName;
firstcolor.value = SelectedItem.swatches[i].colorName;
let firstcolorDiv = document.createElement("div");
firstcolorDiv.style.background = SelectedItem.swatches[i].colorCode;
firstcolorDiv.setAttribute("id", "smallColorDiv");
let colorName = document.createElement("p");
colorName.setAttribute("id", "brand");
colorName.innerText = SelectedItem.swatches[i].colorName;
document.querySelector("#ColorSelect").append(firstcolor);
document.querySelector("#AvailableColors").append(firstcolorDiv, colorName);
}
let AddedToBag = JSON.parse(localStorage.getItem("Cart")) || [];
let ArrSC = JSON.parse(localStorage.getItem("SC")) || [];
document
.querySelector("#AddToCartButton")
.addEventListener("click", function () {
GoToCart();
});
function GoToCart() {
let Selectedsize=document.querySelector("#SizeSelect").value
let Selectedcolor=document.querySelector("#ColorSelect").value
if(Selectedsize!=="" && Selectedcolor!=="" ){
let SizeColorArr = {
size:Selectedsize,
color:Selectedcolor
};
ArrSC.push(SizeColorArr);
alert("Product Added to your Bag !!");
AddedToBag.push(SelectedItem);
localStorage.setItem("SC", JSON.stringify(ArrSC));
localStorage.setItem("Cart", JSON.stringify(AddedToBag));
}else{
alert(" Please Select Size and Color !!")
}
}
document.addEventListener("keydown", SearchCategory);
function SearchCategory(e) {
if (e.key == "Enter") {
let Keyword = document.querySelector("#search").value;
window.location.href="./womes's_page.html"
let link = `https://www2.hm.com/en_in/women/shop-by-product/${Keyword}/_jcr_content/main/productlisting.display.json?sort=stock&image-size=small&image=model&offset=36&page-size=36`;
// document.querySelector("#Pickone").innerHTML = null;
ClothMap(link);
}
}