dschandra commited on
Commit
bcd9d8c
·
verified ·
1 Parent(s): b161656

Update templates/Menu.html

Browse files
Files changed (1) hide show
  1. templates/Menu.html +31 -8
templates/Menu.html CHANGED
@@ -251,16 +251,20 @@
251
  </div>
252
  <h3>${item.Name}</h3>
253
  <p class="price">$${item.Price__c}</p>
254
- <div class="rating">
255
- ⭐ 4.2 (206)
256
- </div>
257
  <button class="save-btn">❤️ Save to Eatlist</button>
258
  <p class="description">${item.Description__c}</p>
259
  </div>
260
  <div class="add-container">
261
  <img class="menu-img" src="${item.Image1__c}" alt="${item.Name}">
262
- <button class="add-btn" onclick='addToCart(${JSON.stringify(item)})'>ADD</button>
263
- <p class="customizable" style="position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%);">Customisable</p>
 
 
 
 
 
 
264
  </div>
265
  `;
266
  menuContainer.appendChild(menuItem);
@@ -287,9 +291,28 @@
287
 
288
  // Function to handle adding an item to the cart
289
  function addToCart(item) {
290
- cart.push(item); // Add item to cart array
291
- console.log("Cart:", cart); // Log updated cart
292
- alert(`${item.Name} added to cart!`); // Alert user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  }
294
 
295
  </script>
 
251
  </div>
252
  <h3>${item.Name}</h3>
253
  <p class="price">$${item.Price__c}</p>
254
+ <div class="rating">⭐ 4.2 (206)</div>
 
 
255
  <button class="save-btn">❤️ Save to Eatlist</button>
256
  <p class="description">${item.Description__c}</p>
257
  </div>
258
  <div class="add-container">
259
  <img class="menu-img" src="${item.Image1__c}" alt="${item.Name}">
260
+ ${cart[item.Name] ? `
261
+ <div class="quantity-control">
262
+ <button onclick="decreaseQuantity('${item.Name}')">-</button>
263
+ <span>${cart[item.Name].quantity}</span>
264
+ <button onclick="increaseQuantity('${item.Name}')">+</button>
265
+ </div>`
266
+ : `<button class="add-btn" onclick='addToCart(${JSON.stringify(item)})'>ADD</button>`}
267
+ <p class="customizable" style="text-align: center; margin-top: 10px;">Customisable</p>
268
  </div>
269
  `;
270
  menuContainer.appendChild(menuItem);
 
291
 
292
  // Function to handle adding an item to the cart
293
  function addToCart(item) {
294
+ if (cart[item.Name]) {
295
+ cart[item.Name].quantity += 1;
296
+ } else {
297
+ cart[item.Name] = { ...item, quantity: 1 };
298
+ }
299
+ displayMenu(filteredMenu); // Refresh menu UI to update button
300
+ }
301
+
302
+ // Function to increase quantity
303
+ function increaseQuantity(name) {
304
+ cart[name].quantity += 1;
305
+ displayMenu(filteredMenu);
306
+ }
307
+
308
+ // Function to decrease quantity
309
+ function decreaseQuantity(name) {
310
+ if (cart[name].quantity > 1) {
311
+ cart[name].quantity -= 1;
312
+ } else {
313
+ delete cart[name]; // Remove item from cart if quantity is 0
314
+ }
315
+ displayMenu(filteredMenu);
316
  }
317
 
318
  </script>