-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingleProduct.js
43 lines (33 loc) · 1.28 KB
/
singleProduct.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
import { fetchProduct } from './fetchProduct.js';
import { displayProduct } from './assignDataOfUser.js';
import CreateReviews from './Reviews.js';
import CardOperations from './CardOperations.js'
const imgConatiner=document.getElementsByClassName('image')[0];
document.addEventListener('DOMContentLoaded', async (event) => {
imgConatiner.style.display="block";
// Check if we are on the singleProduct.html page
if (window.location.pathname.includes('singleProduct.html')) {
// Extract product ID from the query string
const urlParams = new URLSearchParams(window.location.search);
const productId = urlParams.get('id');
if (productId) {
// Display the single product that was clicked.
const product = await fetchProduct(productId);
if (product) {
displayProduct(product);
CreateReviews(product);
}
} else {
console.error('Product ID not found in the URL');
}
}
});
CardOperations();
// Function Display the value to show the number of items added to the cart
addCart.addEventListener('click',function(){
if(finalNum === 1){
cartNum.textContent = "1";
}else{
cartNum.textContent = finalNum
}
});