`✅ 1. PRODUCER – Update Order Status
HTML (producer dashboard)
{% for o in orders %}
<p>{{ o.name }} x{{ o.qty }}</p>
<p>Status: {{ o.status }}</p>
{% if o.status == 'pending' %}
Mark as Shipped
Cancel
{% endif %}
{% endfor %}
JavaScript
function updateStatus(id, status) {
fetch('/update_order_status', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: id, status: status })
})
.then(res => res.json())
.then(data => {
if (data.success) location.reload();
});
}
Flask
@app.route('/update_order_status', methods=['POST'])
def update_order_status():
if session.get('role') != 'producer':
return {'success': False}
data = request.get_json()
q("""
UPDATE order_items
SET status=%s
WHERE id=%s
""", (data['status'], data['id']), write=True)
return {'success': True}
✅ 2. PRODUCER – Upload New Product
HTML
Add Product
Flask
@app.route('/add_product', methods=['POST'])
def add_product():
if session.get('role') != 'producer':
return redirect('/')
q("""
INSERT INTO products(name, price, producer_id)
VALUES(%s,%s,%s)
""", (
request.form['name'],
request.form['price'],
session['uid']
), write=True)
return redirect('/producer')
✅ 3. CUSTOMER – Cancel Order
HTML (customer dashboard)
{% for o in orders %}
<p>{{ o.name }} x{{ o.qty }}</p>
<p>Status: {{ o.status }}</p>
{% if o.status == 'pending' %}
Cancel
{% endif %}
{% endfor %}
JavaScript
function cancelOrder(id) {
fetch('/cancel_order', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: id })
})
.then(res => res.json())
.then(data => {
if (data.success) location.reload();
});
}
Flask
@app.route('/cancel_order', methods=['POST'])
def cancel_order():
if not session.get('uid'):
return {'success': False}
data = request.get_json()
# ensure customer owns the order
q("""
UPDATE order_items oi
JOIN orders o ON oi.order_id = o.id
SET oi.status='cancelled'
WHERE oi.id=%s AND o.customer_id=%s
""", (data['id'], session['uid']), write=True)
return {'success': True}
✅ 4. CSS (status colours)
.order {
padding: 10px;
margin: 10px 0;
color: white;
}
.order.pending { background: orange; }
.order.shipped { background: green; }
.order.cancelled { background: red; }`
Top comments (0)