Spaces:
Sleeping
Sleeping
Update templates/order_history.html
Browse files- templates/order_history.html +29 -18
templates/order_history.html
CHANGED
@@ -95,17 +95,30 @@
|
|
95 |
<div class="order-item-title">{{ item_parts[0].strip() }}</div>
|
96 |
<div><small class="text-muted">Quantity: {{ item_parts[1].strip() }}</small></div>
|
97 |
</div>
|
98 |
-
<
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
104 |
</div>
|
105 |
{% endfor %}
|
106 |
{% endfor %}
|
107 |
{% else %}
|
108 |
-
<p class="text-center">No
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
{% endif %}
|
110 |
</div>
|
111 |
</div>
|
@@ -114,13 +127,12 @@
|
|
114 |
|
115 |
<script>
|
116 |
function addToCart(itemName) {
|
117 |
-
// Get the price from the button's data-
|
118 |
-
const
|
119 |
-
const
|
120 |
-
const
|
121 |
-
const
|
122 |
-
const
|
123 |
-
const instructions = ""; // This could be user-provided instructions for the item
|
124 |
|
125 |
if (!itemPrice || !itemImage || !itemName || !category || !section) {
|
126 |
alert('Missing required item data.');
|
@@ -128,15 +140,15 @@
|
|
128 |
}
|
129 |
|
130 |
// Ensure the price is explicitly treated as a string
|
131 |
-
const itemPriceStr = String(itemPrice); //
|
132 |
|
133 |
// Create a JSON object to send to the server
|
134 |
const dataToSend = {
|
135 |
itemName: itemName, // Item name to be reordered
|
136 |
itemPrice: itemPriceStr, // Price as a string
|
137 |
itemImage: itemImage, // Image URL of the item
|
138 |
-
addons:
|
139 |
-
instructions:
|
140 |
category: category, // Category of the item
|
141 |
section: section // Section of the item
|
142 |
};
|
@@ -161,7 +173,6 @@
|
|
161 |
alert('An error occurred: ' + error);
|
162 |
});
|
163 |
}
|
164 |
-
|
165 |
</script>
|
166 |
|
167 |
</body>
|
|
|
95 |
<div class="order-item-title">{{ item_parts[0].strip() }}</div>
|
96 |
<div><small class="text-muted">Quantity: {{ item_parts[1].strip() }}</small></div>
|
97 |
</div>
|
98 |
+
<button class="reorder-button"
|
99 |
+
onclick="addToCart('{{ item_parts[0].strip() }}')"
|
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 |
+
data-section="Curries"> <!-- Example section -->
|
105 |
+
Reorder
|
106 |
+
</button>
|
107 |
+
|
108 |
</div>
|
109 |
{% endfor %}
|
110 |
{% endfor %}
|
111 |
{% else %}
|
112 |
+
<p class="text-center">No or<button class="reorder-button"
|
113 |
+
onclick="addToCart('{{ item_parts[0].strip() }}')"
|
114 |
+
id="{{ item_parts[0].strip() }}"
|
115 |
+
data-price="{{ item_parts[3].strip().replace('Price:', '') }}"
|
116 |
+
data-image="{{ item_parts[4].strip().replace('Image:', '') }}"
|
117 |
+
data-category="Main Course" <!-- Example category -->
|
118 |
+
data-section="Curries"> <!-- Example section -->
|
119 |
+
Reorder
|
120 |
+
</button>
|
121 |
+
ders found in your history.</p>
|
122 |
{% endif %}
|
123 |
</div>
|
124 |
</div>
|
|
|
127 |
|
128 |
<script>
|
129 |
function addToCart(itemName) {
|
130 |
+
// Get the price, image, category, and section from the button's data- attributes
|
131 |
+
const button = document.getElementById(itemName); // Get the button element
|
132 |
+
const itemPrice = button.dataset.price; // Get price from data-price attribute
|
133 |
+
const itemImage = button.dataset.image; // Get image from data-image attribute
|
134 |
+
const category = button.dataset.category; // Get category from data-category attribute
|
135 |
+
const section = button.dataset.section; // Get section from data-section attribute
|
|
|
136 |
|
137 |
if (!itemPrice || !itemImage || !itemName || !category || !section) {
|
138 |
alert('Missing required item data.');
|
|
|
140 |
}
|
141 |
|
142 |
// Ensure the price is explicitly treated as a string
|
143 |
+
const itemPriceStr = String(itemPrice); // Convert price to string
|
144 |
|
145 |
// Create a JSON object to send to the server
|
146 |
const dataToSend = {
|
147 |
itemName: itemName, // Item name to be reordered
|
148 |
itemPrice: itemPriceStr, // Price as a string
|
149 |
itemImage: itemImage, // Image URL of the item
|
150 |
+
addons: [], // List of add-ons (empty for now)
|
151 |
+
instructions: "", // Instructions for the item (empty for now)
|
152 |
category: category, // Category of the item
|
153 |
section: section // Section of the item
|
154 |
};
|
|
|
173 |
alert('An error occurred: ' + error);
|
174 |
});
|
175 |
}
|
|
|
176 |
</script>
|
177 |
|
178 |
</body>
|