-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomeProductCards.js
45 lines (36 loc) · 1.57 KB
/
homeProductCards.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
import { addToCart } from "./addToCart";
import { homeQuantityToggle } from "./homeQuantityToggle";
const productContainer = document.querySelector("#productContainer");
const productTemplate = document.querySelector("#productTemplate");
export const showProductContainer = (products) => {
if (!products) {
return false;
}
products.forEach((curProd) => {
const { brand, category, description, id, image, name, price, stock } =
curProd;
const productClone = document.importNode(productTemplate.content, true);
productClone.querySelector("#cardValue").setAttribute("id", `card${id}`);
productClone.querySelector(".category").textContent = category;
productClone.querySelector(".productName").textContent = name;
productClone.querySelector(".productImage").src = image;
productClone.querySelector(".productImage").alt = name;
productClone.querySelector(".productStock").textContent = stock;
productClone.querySelector(".productDescription").textContent = description;
productClone.querySelector(".productPrice").textContent = `₹${price}`;
productClone.querySelector(".productActualPrice").textContent = `₹${
price * 2
}`;
productClone
.querySelector(".stockElement")
.addEventListener("click", (event) => {
homeQuantityToggle(event, id, stock);
});
productClone
.querySelector(".add-to-cart-button")
.addEventListener("click", (event) => {
addToCart(event, id, stock);
});
productContainer.append(productClone);
});
};