Update templates/search.html
Browse files- templates/search.html +186 -2
templates/search.html
CHANGED
@@ -163,8 +163,17 @@
|
|
163 |
<h2>Search Results</h2>
|
164 |
<div id="searchResults" class="row">
|
165 |
{% for item in all_items %}
|
166 |
-
<div class="col-md-6 mb-4 search-item"
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
<div class="card menu-card">
|
169 |
<img src="{{ item.Image2__c | default(item.Image1__c) | default('/static/placeholder.jpg') }}"
|
170 |
class="card-img-top menu-video" alt="{{ item.Name }}" style="height: 200px; object-fit: cover;">
|
@@ -184,6 +193,46 @@
|
|
184 |
<div id="autocompleteSuggestions" class="autocomplete-suggestions"></div>
|
185 |
</div>
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
188 |
<script>
|
189 |
const menuItems = [
|
@@ -254,7 +303,142 @@
|
|
254 |
suggestionsContainer.style.display = 'none';
|
255 |
}
|
256 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
</script>
|
259 |
</body>
|
260 |
</html>
|
|
|
163 |
<h2>Search Results</h2>
|
164 |
<div id="searchResults" class="row">
|
165 |
{% for item in all_items %}
|
166 |
+
<div class="col-md-6 mb-4 search-item"
|
167 |
+
data-name="{{ item.Name | lower }}"
|
168 |
+
data-section="{{ item.Section__c | lower }}"
|
169 |
+
data-price="{{ item.Price__c | default('0.00') }}"
|
170 |
+
data-image="{{ item.Image2__c | default(item.Image1__c) | default('/static/placeholder.jpg') }}"
|
171 |
+
data-description="{{ item.Description__c | default('No description') | e }}"
|
172 |
+
data-ingredients="{{ item.IngredientsInfo__c | default('Not specified') | e }}"
|
173 |
+
data-nutrition="{{ item.NutritionalInfo__c | default('Not available') | e }}"
|
174 |
+
data-allergens="{{ item.Allergens__c | default('None listed') | e }}"
|
175 |
+
data-category="{{ item.Category__c | default('') }}"
|
176 |
+
onclick="triggerItemModal(this)">
|
177 |
<div class="card menu-card">
|
178 |
<img src="{{ item.Image2__c | default(item.Image1__c) | default('/static/placeholder.jpg') }}"
|
179 |
class="card-img-top menu-video" alt="{{ item.Name }}" style="height: 200px; object-fit: cover;">
|
|
|
193 |
<div id="autocompleteSuggestions" class="autocomplete-suggestions"></div>
|
194 |
</div>
|
195 |
|
196 |
+
<!-- Include the Item Modal from Menu HTML -->
|
197 |
+
<div class="modal fade" id="itemModal" tabindex="-1" aria-labelledby="itemModalLabel" aria-hidden="true">
|
198 |
+
<div class="modal-dialog modal-dialog-centered">
|
199 |
+
<div class="modal-content">
|
200 |
+
<div class="modal-header">
|
201 |
+
<h5 class="modal-title" id="itemModalLabel">Item Details</h5>
|
202 |
+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
203 |
+
</div>
|
204 |
+
<div class="modal-body">
|
205 |
+
<img id="modal-img" class="img-fluid rounded mb-3 d-block mx-auto" alt="Item Image" style="max-height: 200px; object-fit: cover;">
|
206 |
+
<h5 id="modal-name" class="fw-bold text-center"></h5>
|
207 |
+
<p id="modal-price" class="text-muted text-center"></p>
|
208 |
+
<p id="modal-description" class="text-secondary"></p>
|
209 |
+
<div class="nutritional-info">
|
210 |
+
<strong>Ingredients:</strong> <span id="modal-ingredients"></span><br>
|
211 |
+
<strong>Nutrition:</strong> <span id="modal-nutrition"></span><br>
|
212 |
+
<strong>Allergens:</strong> <span id="modal-allergens"></span>
|
213 |
+
</div>
|
214 |
+
<div id="modal-addons" class="modal-addons mt-4">
|
215 |
+
<h6>Customization Options</h6>
|
216 |
+
<div id="addons-list" class="addons-container">Loading customization options...</div>
|
217 |
+
</div>
|
218 |
+
<div class="mt-4">
|
219 |
+
<h6>Custom Request</h6>
|
220 |
+
<textarea id="modal-instructions" class="form-control" placeholder="Enter any special instructions here..."></textarea>
|
221 |
+
</div>
|
222 |
+
<span id="modal-section" data-section="" data-category="" style="display: none;"></span>
|
223 |
+
</div>
|
224 |
+
<div class="modal-footer d-flex align-items-center justify-content-between">
|
225 |
+
<div class="d-flex align-items-center gap-2">
|
226 |
+
<button type="button" class="btn btn-outline-secondary" id="decreaseQuantity">-</button>
|
227 |
+
<input type="text" class="form-control text-center" id="quantityInput" value="1" readonly style="width: 50px;"/>
|
228 |
+
<button type="button" class="btn btn-outline-secondary" id="increaseQuantity">+</button>
|
229 |
+
</div>
|
230 |
+
<button type="button" class="btn btn-primary" onclick="addToCartFromModal()">Add to Cart</button>
|
231 |
+
</div>
|
232 |
+
</div>
|
233 |
+
</div>
|
234 |
+
</div>
|
235 |
+
|
236 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
237 |
<script>
|
238 |
const menuItems = [
|
|
|
303 |
suggestionsContainer.style.display = 'none';
|
304 |
}
|
305 |
});
|
306 |
+
|
307 |
+
// Quantity controls for modal
|
308 |
+
const decreaseBtn = document.getElementById('decreaseQuantity');
|
309 |
+
const increaseBtn = document.getElementById('increaseQuantity');
|
310 |
+
const quantityInput = document.getElementById('quantityInput');
|
311 |
+
decreaseBtn.addEventListener('click', function () {
|
312 |
+
let currentQuantity = parseInt(quantityInput.value);
|
313 |
+
if (currentQuantity > 1) {
|
314 |
+
currentQuantity--;
|
315 |
+
quantityInput.value = currentQuantity;
|
316 |
+
}
|
317 |
+
});
|
318 |
+
increaseBtn.addEventListener('click', function () {
|
319 |
+
let currentQuantity = parseInt(quantityInput.value);
|
320 |
+
currentQuantity++;
|
321 |
+
quantityInput.value = currentQuantity;
|
322 |
+
});
|
323 |
});
|
324 |
+
|
325 |
+
function triggerItemModal(element) {
|
326 |
+
const name = element.querySelector('.card-title').innerText;
|
327 |
+
const price = element.getAttribute('data-price');
|
328 |
+
const image = element.getAttribute('data-image');
|
329 |
+
const description = element.getAttribute('data-description');
|
330 |
+
const ingredients = element.getAttribute('data-ingredients');
|
331 |
+
const nutrition = element.getAttribute('data-nutrition');
|
332 |
+
const allergens = element.getAttribute('data-allergens');
|
333 |
+
const section = element.getAttribute('data-section');
|
334 |
+
const selectedCategory = element.getAttribute('data-category');
|
335 |
+
|
336 |
+
// Populate modal
|
337 |
+
document.getElementById('modal-name').innerText = name;
|
338 |
+
document.getElementById('modal-price').innerText = `$${price}`;
|
339 |
+
document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
|
340 |
+
document.getElementById('modal-description').innerText = description || 'No description available.';
|
341 |
+
document.getElementById('modal-ingredients').innerText = ingredients || 'Not specified';
|
342 |
+
document.getElementById('modal-nutrition').innerText = nutrition || 'Not available';
|
343 |
+
document.getElementById('modal-allergens').innerText = allergens || 'None listed';
|
344 |
+
document.getElementById('modal-instructions').value = '';
|
345 |
+
const modalSectionEl = document.getElementById('modal-section');
|
346 |
+
modalSectionEl.setAttribute('data-section', section);
|
347 |
+
modalSectionEl.setAttribute('data-category', selectedCategory);
|
348 |
+
document.getElementById('quantityInput').value = 1;
|
349 |
+
|
350 |
+
// Fetch addons (assuming this endpoint exists)
|
351 |
+
fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
|
352 |
+
.then(response => response.json())
|
353 |
+
.then(data => {
|
354 |
+
const addonsList = document.getElementById('addons-list');
|
355 |
+
addonsList.innerHTML = '';
|
356 |
+
if (!data.success || !data.addons || data.addons.length === 0) {
|
357 |
+
addonsList.innerHTML = '<p>No customization options available.</p>';
|
358 |
+
return;
|
359 |
+
}
|
360 |
+
data.addons.forEach(addon => {
|
361 |
+
const sectionDiv = document.createElement('div');
|
362 |
+
sectionDiv.classList.add('addon-section');
|
363 |
+
const title = document.createElement('h6');
|
364 |
+
title.innerText = addon.name;
|
365 |
+
sectionDiv.appendChild(title);
|
366 |
+
const optionsContainer = document.createElement('div');
|
367 |
+
addon.options.forEach((option, index) => {
|
368 |
+
const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
|
369 |
+
const listItem = document.createElement('div');
|
370 |
+
listItem.classList.add('form-check');
|
371 |
+
listItem.innerHTML = `
|
372 |
+
<input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
|
373 |
+
data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
|
374 |
+
<label class="form-check-label" for="${optionId}">
|
375 |
+
${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
|
376 |
+
</label>
|
377 |
+
`;
|
378 |
+
optionsContainer.appendChild(listItem);
|
379 |
+
});
|
380 |
+
sectionDiv.appendChild(optionsContainer);
|
381 |
+
addonsList.appendChild(sectionDiv);
|
382 |
+
});
|
383 |
+
})
|
384 |
+
.catch(err => {
|
385 |
+
console.error('Error fetching add-ons:', err);
|
386 |
+
document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
|
387 |
+
});
|
388 |
+
|
389 |
+
// Show modal
|
390 |
+
const modal = new bootstrap.Modal(document.getElementById('itemModal'));
|
391 |
+
modal.show();
|
392 |
+
}
|
393 |
+
|
394 |
+
function addToCartFromModal() {
|
395 |
+
const itemName = document.getElementById('modal-name').innerText;
|
396 |
+
const itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
397 |
+
const itemImage = document.getElementById('modal-img').src;
|
398 |
+
const instructions = document.getElementById('modal-instructions').value.trim();
|
399 |
+
const quantity = parseInt(document.getElementById('quantityInput').value);
|
400 |
+
const section = document.getElementById('modal-section').getAttribute('data-section');
|
401 |
+
const selectedCategory = document.getElementById('modal-section').getAttribute('data-category');
|
402 |
+
const addons = Array.from(document.querySelectorAll('.addon-option:checked')).map(cb => ({
|
403 |
+
name: cb.getAttribute('data-name'),
|
404 |
+
price: parseFloat(cb.getAttribute('data-price') || 0)
|
405 |
+
}));
|
406 |
+
|
407 |
+
const cartPayload = {
|
408 |
+
itemName: itemName,
|
409 |
+
itemPrice: itemPrice,
|
410 |
+
itemImage: itemImage,
|
411 |
+
section: section,
|
412 |
+
category: selectedCategory,
|
413 |
+
addons: addons,
|
414 |
+
instructions: instructions,
|
415 |
+
quantity: quantity
|
416 |
+
};
|
417 |
+
|
418 |
+
fetch('/cart/add', {
|
419 |
+
method: 'POST',
|
420 |
+
headers: {
|
421 |
+
'Content-Type': 'application/json',
|
422 |
+
},
|
423 |
+
body: JSON.stringify(cartPayload)
|
424 |
+
})
|
425 |
+
.then(response => response.json())
|
426 |
+
.then(data => {
|
427 |
+
if (data.success) {
|
428 |
+
alert('Item added to cart successfully!');
|
429 |
+
const modal = bootstrap.Modal.getInstance(document.getElementById('itemModal'));
|
430 |
+
modal.hide();
|
431 |
+
// Optionally update cart UI here if needed
|
432 |
+
} else {
|
433 |
+
console.error('Failed to add item to cart:', data.error);
|
434 |
+
alert(data.error || 'Failed to add item to cart.');
|
435 |
+
}
|
436 |
+
})
|
437 |
+
.catch(err => {
|
438 |
+
console.error('Error adding item to cart:', err);
|
439 |
+
alert('Error adding item to cart.');
|
440 |
+
});
|
441 |
+
}
|
442 |
</script>
|
443 |
</body>
|
444 |
</html>
|