Rammohan0504 commited on
Commit
5599fb4
·
verified ·
1 Parent(s): 9e28083

Update templates/order_history.html

Browse files
Files changed (1) hide show
  1. 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
- <div class="order-item-price">${{ item_parts[3].strip().replace('Price:', '') }}</div>
99
- <button class="reorder-button" onclick="addToCart('{{ item_parts[0].strip() }}')"
100
- id="{{ item_parts[0].strip() }}"
101
- data-price="{{ item_parts[3].strip().replace('Price:', '') }}">
102
- Reorder
103
- </button>
 
 
 
 
104
  </div>
105
  {% endfor %}
106
  {% endfor %}
107
  {% else %}
108
- <p class="text-center">No orders found in your history.</p>
 
 
 
 
 
 
 
 
 
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-price attribute
118
- const itemPrice = document.getElementById(itemName).dataset.price;
119
- const itemImage = document.getElementById(itemName).dataset.image; // Get image URL
120
- const category = document.getElementById(itemName).dataset.category; // Get item category
121
- const section = document.getElementById(itemName).dataset.section; // Get item section
122
- const addons = []; // This could be an array of selected addons
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); // Explicitly convert to string
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: addons, // List of add-ons (empty for now, can be dynamically populated)
139
- instructions: instructions, // Instructions for the item (empty for now)
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>