Group cart tickets by event with +/- quantity buttons
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 51s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 51s
- Cart page groups tickets by entry+type instead of listing individually - Each group shows event name, type, date, qty with +/- buttons, line total - New POST /cart/ticket-quantity/ route for adjusting from cart page - Summary includes ticket quantities in Items count Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -81,6 +81,28 @@ def register(url_prefix: str) -> Blueprint:
|
||||
resp.headers["HX-Refresh"] = "true"
|
||||
return resp
|
||||
|
||||
@bp.post("/ticket-quantity/")
|
||||
async def update_ticket_quantity():
|
||||
"""Adjust reserved ticket count (+/- pattern, like products)."""
|
||||
ident = current_cart_identity()
|
||||
form = await request.form
|
||||
entry_id = int(form.get("entry_id", 0))
|
||||
count = max(int(form.get("count", 0)), 0)
|
||||
tt_raw = (form.get("ticket_type_id") or "").strip()
|
||||
ticket_type_id = int(tt_raw) if tt_raw else None
|
||||
|
||||
await services.calendar.adjust_ticket_quantity(
|
||||
g.s, entry_id, count,
|
||||
user_id=ident["user_id"],
|
||||
session_id=ident["session_id"],
|
||||
ticket_type_id=ticket_type_id,
|
||||
)
|
||||
await g.s.flush()
|
||||
|
||||
resp = await make_response("", 200)
|
||||
resp.headers["HX-Refresh"] = "true"
|
||||
return resp
|
||||
|
||||
@bp.post("/delete/<int:product_id>/")
|
||||
async def delete_item(product_id: int):
|
||||
ident = current_cart_identity()
|
||||
|
||||
@@ -14,6 +14,7 @@ from .services import (
|
||||
ticket_total,
|
||||
)
|
||||
from .services.page_cart import get_cart_for_page, get_calendar_entries_for_page, get_tickets_for_page
|
||||
from .services.ticket_groups import group_tickets
|
||||
from .services.checkout import (
|
||||
create_order_from_cart,
|
||||
build_sumup_description,
|
||||
@@ -33,12 +34,15 @@ def register(url_prefix: str) -> Blueprint:
|
||||
cal_entries = await get_calendar_entries_for_page(g.s, post.id)
|
||||
page_tickets = await get_tickets_for_page(g.s, post.id)
|
||||
|
||||
ticket_groups = group_tickets(page_tickets)
|
||||
|
||||
tpl_ctx = dict(
|
||||
page_post=post,
|
||||
page_config=getattr(g, "page_config", None),
|
||||
cart=cart,
|
||||
calendar_cart_entries=cal_entries,
|
||||
ticket_cart_entries=page_tickets,
|
||||
ticket_groups=ticket_groups,
|
||||
total=total,
|
||||
calendar_total=calendar_total,
|
||||
ticket_total=ticket_total,
|
||||
|
||||
43
bp/cart/services/ticket_groups.py
Normal file
43
bp/cart/services/ticket_groups.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Group individual TicketDTOs by (entry_id, ticket_type_id) for cart display."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
def group_tickets(tickets) -> list[dict]:
|
||||
"""
|
||||
Group a flat list of TicketDTOs into aggregate rows.
|
||||
|
||||
Returns list of dicts:
|
||||
{
|
||||
"entry_id": int,
|
||||
"entry_name": str,
|
||||
"entry_start_at": datetime,
|
||||
"entry_end_at": datetime | None,
|
||||
"ticket_type_id": int | None,
|
||||
"ticket_type_name": str | None,
|
||||
"price": Decimal | None,
|
||||
"quantity": int,
|
||||
"line_total": float,
|
||||
}
|
||||
"""
|
||||
groups: OrderedDict[tuple, dict] = OrderedDict()
|
||||
|
||||
for tk in tickets:
|
||||
key = (tk.entry_id, getattr(tk, "ticket_type_id", None))
|
||||
if key not in groups:
|
||||
groups[key] = {
|
||||
"entry_id": tk.entry_id,
|
||||
"entry_name": tk.entry_name,
|
||||
"entry_start_at": tk.entry_start_at,
|
||||
"entry_end_at": tk.entry_end_at,
|
||||
"ticket_type_id": getattr(tk, "ticket_type_id", None),
|
||||
"ticket_type_name": tk.ticket_type_name,
|
||||
"price": tk.price,
|
||||
"quantity": 0,
|
||||
"line_total": 0,
|
||||
}
|
||||
groups[key]["quantity"] += 1
|
||||
groups[key]["line_total"] += float(tk.price or 0)
|
||||
|
||||
return list(groups.values())
|
||||
Reference in New Issue
Block a user