Spaces:
Sleeping
Sleeping
Update templates/order_history.html
Browse files- templates/order_history.html +46 -46
templates/order_history.html
CHANGED
@@ -100,7 +100,7 @@
|
|
100 |
id="{{ item_parts[0].strip() }}"
|
101 |
data-price="{{ item_parts[3].strip().replace('Price:', '') }}"
|
102 |
data-image="{{ item_parts[4].strip().replace('Image:', '') }}"
|
103 |
-
data-category="Main Course" <!-- Example category -->
|
104 |
Reorder
|
105 |
</button>
|
106 |
|
@@ -120,52 +120,52 @@
|
|
120 |
|
121 |
<script>
|
122 |
function addToCart(itemName) {
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
alert('Error: ' + data.error);
|
163 |
-
}
|
164 |
-
})
|
165 |
-
.catch(error => {
|
166 |
-
alert('An error occurred: ' + error);
|
167 |
-
});
|
168 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
</script>
|
170 |
|
171 |
</body>
|
|
|
100 |
id="{{ item_parts[0].strip() }}"
|
101 |
data-price="{{ item_parts[3].strip().replace('Price:', '') }}"
|
102 |
data-image="{{ item_parts[4].strip().replace('Image:', '') }}"
|
103 |
+
data-category="Main Course" <!-- Example category -->
|
104 |
Reorder
|
105 |
</button>
|
106 |
|
|
|
120 |
|
121 |
<script>
|
122 |
function addToCart(itemName) {
|
123 |
+
const button = document.getElementById(itemName); // Get the button element by its ID
|
124 |
+
const itemPrice = button.dataset.price; // Get price from data-price attribute
|
125 |
+
const itemImage = button.dataset.image; // Get image URL from data-image attribute
|
126 |
+
const category = button.dataset.category; // Get category from data-category attribute
|
127 |
+
const section = button.dataset.section; // Get section from data-section attribute
|
128 |
+
|
129 |
+
if (!itemPrice || !itemImage || !itemName || !category || !section) {
|
130 |
+
alert('Missing required item data.');
|
131 |
+
return;
|
132 |
+
}
|
133 |
+
|
134 |
+
// Ensure the price is explicitly treated as a string
|
135 |
+
const itemPriceStr = String(itemPrice); // Explicitly convert to string
|
136 |
+
|
137 |
+
// Create a JSON object to send to the server
|
138 |
+
const dataToSend = {
|
139 |
+
itemName: itemName, // Item name to be reordered
|
140 |
+
itemPrice: itemPriceStr, // Price as a string
|
141 |
+
itemImage: itemImage, // Image URL of the item
|
142 |
+
addons: [], // List of add-ons (empty for now)
|
143 |
+
instructions: "", // Instructions for the item (empty for now)
|
144 |
+
category: category, // Category of the item
|
145 |
+
section: section // Section of the item
|
146 |
+
};
|
147 |
+
|
148 |
+
// Send the data to the server via a POST request
|
149 |
+
fetch('/cart/add', {
|
150 |
+
method: 'POST',
|
151 |
+
headers: {
|
152 |
+
'Content-Type': 'application/json',
|
153 |
+
},
|
154 |
+
body: JSON.stringify(dataToSend),
|
155 |
+
})
|
156 |
+
.then(response => response.json())
|
157 |
+
.then(data => {
|
158 |
+
if (data.success) {
|
159 |
+
alert('Item added to cart successfully!');
|
160 |
+
} else {
|
161 |
+
alert('Error: ' + data.error);
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
}
|
163 |
+
})
|
164 |
+
.catch(error => {
|
165 |
+
alert('An error occurred: ' + error);
|
166 |
+
});
|
167 |
+
}
|
168 |
+
|
169 |
</script>
|
170 |
|
171 |
</body>
|