mirror of
https://github.com/Alvin-Zilverstand/Schoolkantine.git
synced 2026-03-06 21:36:27 +01:00
cart icon
This commit is contained in:
@@ -1,20 +1,17 @@
|
|||||||
|
|
||||||
|
|
||||||
// Array to hold items added to the shopping cart
|
// Array to hold items added to the shopping cart
|
||||||
const cart = [];
|
const cart = [];
|
||||||
|
let cartCount = 0; // Initialize cart count
|
||||||
|
|
||||||
|
// Function to add an item to the shopping cart
|
||||||
|
|
||||||
// Functie om een item aan het winkelwagentje toe te voegen
|
|
||||||
function addToCart(item) {
|
function addToCart(item) {
|
||||||
cart.unshift(item); // Add item to the beginning of the cart array
|
cart.unshift(item); // Add item to the beginning of the cart array
|
||||||
updateCart();
|
updateCart();
|
||||||
|
cartCount++; // Increment cart count
|
||||||
|
updateCartCountDisplay(); // Update the cart count display
|
||||||
closeModal();
|
closeModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to update the shopping cart display
|
||||||
|
|
||||||
// Functie om het winkelwagentje bij te werken
|
|
||||||
function updateCart() {
|
function updateCart() {
|
||||||
const cartItemsContainer = document.getElementById("cart-items");
|
const cartItemsContainer = document.getElementById("cart-items");
|
||||||
cartItemsContainer.innerHTML = '';
|
cartItemsContainer.innerHTML = '';
|
||||||
@@ -41,18 +38,29 @@ function updateCart() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to remove an item from the shopping cart
|
||||||
// Functie om een item uit het winkelwagentje te verwijderen
|
|
||||||
function removeFromCart(index) {
|
function removeFromCart(index) {
|
||||||
cart.splice(index, 1);
|
cart.splice(index, 1);
|
||||||
updateCart();
|
updateCart();
|
||||||
|
cartCount--; // Decrement cart count
|
||||||
|
updateCartCountDisplay(); // Update the cart count display
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial call to updateCart to ensure the button is hidden on page load
|
// Function to update the cart count display
|
||||||
updateCart();
|
function updateCartCountDisplay() {
|
||||||
|
const cartCountElement = document.getElementById("cart-count"); // Get the element to display the count
|
||||||
|
if (cartCountElement) { // Check if the element exists
|
||||||
|
cartCountElement.textContent = cartCount; // Update the text content with the cart count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Functie om het modaal venster te sluiten
|
|
||||||
|
// Initial calls
|
||||||
|
updateCart();
|
||||||
|
updateCartCountDisplay(); // Initialize the cart count on page load
|
||||||
|
|
||||||
|
|
||||||
|
// Function to close the modal window
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
document.getElementById('modal').style.display = 'none';
|
document.getElementById('modal').style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
<!-- Winkelwagen icoon -->
|
<!-- Winkelwagen icoon -->
|
||||||
<div class="cart-icon">
|
<div class="cart-icon">
|
||||||
<i class="fas fa-shopping-cart"></i>
|
<i class="fas fa-shopping-cart"></i>
|
||||||
<span class="cart-count">0</span> <!-- Aantal producten -->
|
<span id="cart-count" class="cart-count">0</span> <!-- Aantal producten -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
|
|||||||
Reference in New Issue
Block a user