Add delete endpoint with confirm modal, keep items at quantity 0
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 48s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 48s
- POST /delete/<product_id>/ removes the cart item entirely - POST /quantity/ now clamps at 0 instead of deleting - cart_delete_url Jinja global registered for template Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1
app.py
1
app.py
@@ -100,6 +100,7 @@ def create_app() -> "Quart":
|
||||
])
|
||||
|
||||
app.jinja_env.globals["cart_quantity_url"] = lambda product_id: f"/quantity/{product_id}/"
|
||||
app.jinja_env.globals["cart_delete_url"] = lambda product_id: f"/delete/{product_id}/"
|
||||
|
||||
# --- Page slug hydration (follows events/market app pattern) ---
|
||||
|
||||
|
||||
@@ -72,10 +72,30 @@ def register(url_prefix: str) -> Blueprint:
|
||||
existing = await g.s.scalar(select(CartItem).where(*filters))
|
||||
|
||||
if existing:
|
||||
if count <= 0:
|
||||
await g.s.delete(existing)
|
||||
else:
|
||||
existing.quantity = count
|
||||
existing.quantity = max(count, 0)
|
||||
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()
|
||||
|
||||
filters = [
|
||||
CartItem.deleted_at.is_(None),
|
||||
CartItem.product_id == product_id,
|
||||
]
|
||||
if ident["user_id"] is not None:
|
||||
filters.append(CartItem.user_id == ident["user_id"])
|
||||
else:
|
||||
filters.append(CartItem.session_id == ident["session_id"])
|
||||
|
||||
existing = await g.s.scalar(select(CartItem).where(*filters))
|
||||
|
||||
if existing:
|
||||
await g.s.delete(existing)
|
||||
await g.s.flush()
|
||||
|
||||
resp = await make_response("", 200)
|
||||
|
||||
2
shared
2
shared
Submodule shared updated: 7b55d78214...6db91cb3c1
Reference in New Issue
Block a user