Update templates/menu.html
Browse files- templates/menu.html +47 -1
templates/menu.html
CHANGED
|
@@ -579,7 +579,7 @@ form-check-input addon-option{
|
|
| 579 |
</div>
|
| 580 |
<div>
|
| 581 |
<!-- Add Button on Image -->
|
| 582 |
-
<button class=" btn btn-danger
|
| 583 |
Add
|
| 584 |
</button>
|
| 585 |
</div>
|
|
@@ -892,6 +892,52 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
| 892 |
});
|
| 893 |
});
|
| 894 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 895 |
|
| 896 |
|
| 897 |
</script>
|
|
|
|
| 579 |
</div>
|
| 580 |
<div>
|
| 581 |
<!-- Add Button on Image -->
|
| 582 |
+
<button class=" btn btn-danger" onclick="addToCart('{{ item.Name }}', '{{ item.Price__c }}', '{{ item.Image1__c }}')" >
|
| 583 |
Add
|
| 584 |
</button>
|
| 585 |
</div>
|
|
|
|
| 892 |
});
|
| 893 |
});
|
| 894 |
|
| 895 |
+
|
| 896 |
+
// Create an empty cart if it doesn't exist yet
|
| 897 |
+
if (!localStorage.getItem('cart')) {
|
| 898 |
+
localStorage.setItem('cart', JSON.stringify([]));
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
// Function to add item to the cart
|
| 902 |
+
function addToCart(itemName, itemPrice, itemImage) {
|
| 903 |
+
// Get the cart from localStorage
|
| 904 |
+
let cart = JSON.parse(localStorage.getItem('cart'));
|
| 905 |
+
|
| 906 |
+
// Create the item object to add to the cart
|
| 907 |
+
let item = {
|
| 908 |
+
name: itemName,
|
| 909 |
+
price: itemPrice,
|
| 910 |
+
image: itemImage,
|
| 911 |
+
quantity: 1 // Initial quantity is 1, you can adjust if needed
|
| 912 |
+
};
|
| 913 |
+
|
| 914 |
+
// Check if the item already exists in the cart
|
| 915 |
+
let existingItem = cart.find(cartItem => cartItem.name === itemName);
|
| 916 |
+
|
| 917 |
+
if (existingItem) {
|
| 918 |
+
// If the item already exists, just update the quantity
|
| 919 |
+
existingItem.quantity += 1;
|
| 920 |
+
} else {
|
| 921 |
+
// If the item doesn't exist, add it to the cart
|
| 922 |
+
cart.push(item);
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
// Save the updated cart back to localStorage
|
| 926 |
+
localStorage.setItem('cart', JSON.stringify(cart));
|
| 927 |
+
|
| 928 |
+
// Optional: Update the UI to show the cart count or show a message
|
| 929 |
+
alert(itemName + " has been added to your cart!");
|
| 930 |
+
}
|
| 931 |
+
|
| 932 |
+
// Function to get the cart (optional for showing cart info)
|
| 933 |
+
function getCart() {
|
| 934 |
+
return JSON.parse(localStorage.getItem('cart'));
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
|
| 938 |
+
|
| 939 |
+
|
| 940 |
+
|
| 941 |
|
| 942 |
|
| 943 |
</script>
|