Fix events: use cart-mini fragment instead of local cart template
Events was trying to render _types/cart/_mini.html locally, which only
exists in the cart service. Replace with fetch_fragment("cart", "cart-mini")
calls and add oob param support to the cart-mini fragment.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,7 +32,8 @@ def register():
|
|||||||
g.s, user_id=user_id, session_id=session_id,
|
g.s, user_id=user_id, session_id=session_id,
|
||||||
)
|
)
|
||||||
count = summary.count + summary.calendar_count + summary.ticket_count
|
count = summary.count + summary.calendar_count + summary.ticket_count
|
||||||
return await render_template("fragments/cart_mini.html", cart_count=count)
|
oob = request.args.get("oob", "")
|
||||||
|
return await render_template("fragments/cart_mini.html", cart_count=count, oob=oob)
|
||||||
|
|
||||||
async def _account_nav_item():
|
async def _account_nav_item():
|
||||||
from shared.infrastructure.urls import cart_url
|
from shared.infrastructure.urls import cart_url
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<div id="cart-mini">
|
<div id="cart-mini" {% if oob %}hx-swap-oob="true"{% endif %}>
|
||||||
{% if cart_count == 0 %}
|
{% if cart_count == 0 %}
|
||||||
<div class="h-12 w-12 rounded-full overflow-hidden border border-stone-300 flex-shrink-0">
|
<div class="h-12 w-12 rounded-full overflow-hidden border border-stone-300 flex-shrink-0">
|
||||||
<a
|
<a
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ Routes:
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from quart import Blueprint, g, request, render_template, render_template_string, make_response
|
from quart import Blueprint, g, request, render_template, make_response
|
||||||
|
|
||||||
from shared.browser.app.utils.htmx import is_htmx_request
|
from shared.browser.app.utils.htmx import is_htmx_request
|
||||||
from shared.infrastructure.cart_identity import current_cart_identity
|
from shared.infrastructure.cart_identity import current_cart_identity
|
||||||
from shared.infrastructure.data_client import fetch_data
|
from shared.infrastructure.data_client import fetch_data
|
||||||
from shared.contracts.dtos import CartSummaryDTO, PostDTO, dto_from_dict
|
from shared.contracts.dtos import PostDTO, dto_from_dict
|
||||||
from shared.services.registry import services
|
from shared.services.registry import services
|
||||||
|
|
||||||
|
|
||||||
@@ -125,28 +125,21 @@ def register() -> Blueprint:
|
|||||||
# Load entry DTO for the widget template
|
# Load entry DTO for the widget template
|
||||||
entry = await services.calendar.entry_by_id(g.s, entry_id)
|
entry = await services.calendar.entry_by_id(g.s, entry_id)
|
||||||
|
|
||||||
# Updated cart count for OOB mini-cart
|
# Fetch OOB cart-mini fragment from cart service
|
||||||
summary_params = {}
|
from shared.infrastructure.fragments import fetch_fragment
|
||||||
|
frag_params = {"oob": "1"}
|
||||||
if ident["user_id"] is not None:
|
if ident["user_id"] is not None:
|
||||||
summary_params["user_id"] = ident["user_id"]
|
frag_params["user_id"] = str(ident["user_id"])
|
||||||
if ident["session_id"] is not None:
|
if ident["session_id"] is not None:
|
||||||
summary_params["session_id"] = ident["session_id"]
|
frag_params["session_id"] = ident["session_id"]
|
||||||
raw_summary = await fetch_data("cart", "cart-summary", params=summary_params, required=False)
|
|
||||||
summary = dto_from_dict(CartSummaryDTO, raw_summary) if raw_summary else CartSummaryDTO()
|
|
||||||
cart_count = summary.count + summary.calendar_count + summary.ticket_count
|
|
||||||
|
|
||||||
# Render widget + OOB cart-mini
|
|
||||||
widget_html = await render_template(
|
widget_html = await render_template(
|
||||||
"_types/page_summary/_ticket_widget.html",
|
"_types/page_summary/_ticket_widget.html",
|
||||||
entry=entry,
|
entry=entry,
|
||||||
qty=qty,
|
qty=qty,
|
||||||
ticket_url="/all-tickets/adjust",
|
ticket_url="/all-tickets/adjust",
|
||||||
)
|
)
|
||||||
mini_html = await render_template_string(
|
mini_html = await fetch_fragment("cart", "cart-mini", params=frag_params, required=False)
|
||||||
'{% from "_types/cart/_mini.html" import mini with context %}'
|
|
||||||
'{{ mini(oob="true") }}',
|
|
||||||
cart_count=cart_count,
|
|
||||||
)
|
|
||||||
return await make_response(widget_html + mini_html, 200)
|
return await make_response(widget_html + mini_html, 200)
|
||||||
|
|
||||||
return bp
|
return bp
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from datetime import datetime, timezone
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from quart import (
|
from quart import (
|
||||||
request, render_template, render_template_string, make_response,
|
request, render_template, make_response,
|
||||||
Blueprint, g, redirect, url_for, jsonify,
|
Blueprint, g, redirect, url_for, jsonify,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -219,27 +219,17 @@ def register():
|
|||||||
select(sa_func.count()).select_from(CalendarEntry).where(*cal_filters)
|
select(sa_func.count()).select_from(CalendarEntry).where(*cal_filters)
|
||||||
) or 0
|
) or 0
|
||||||
|
|
||||||
# Get product cart count via HTTP
|
|
||||||
from shared.infrastructure.cart_identity import current_cart_identity
|
from shared.infrastructure.cart_identity import current_cart_identity
|
||||||
from shared.infrastructure.data_client import fetch_data
|
from shared.infrastructure.fragments import fetch_fragment
|
||||||
from shared.contracts.dtos import CartSummaryDTO, dto_from_dict
|
|
||||||
ident = current_cart_identity()
|
ident = current_cart_identity()
|
||||||
summary_params = {}
|
frag_params = {"oob": "1"}
|
||||||
if ident["user_id"] is not None:
|
if ident["user_id"] is not None:
|
||||||
summary_params["user_id"] = ident["user_id"]
|
frag_params["user_id"] = str(ident["user_id"])
|
||||||
if ident["session_id"] is not None:
|
if ident["session_id"] is not None:
|
||||||
summary_params["session_id"] = ident["session_id"]
|
frag_params["session_id"] = ident["session_id"]
|
||||||
raw_summary = await fetch_data("cart", "cart-summary", params=summary_params, required=False)
|
|
||||||
cart_summary = dto_from_dict(CartSummaryDTO, raw_summary) if raw_summary else CartSummaryDTO()
|
|
||||||
product_count = cart_summary.count
|
|
||||||
total_count = product_count + cal_count
|
|
||||||
|
|
||||||
html = await render_template("_types/day/_main_panel.html")
|
html = await render_template("_types/day/_main_panel.html")
|
||||||
mini_html = await render_template_string(
|
mini_html = await fetch_fragment("cart", "cart-mini", params=frag_params, required=False)
|
||||||
'{% from "_types/cart/_mini.html" import mini with context %}'
|
|
||||||
'{{ mini(oob="true") }}',
|
|
||||||
cart_count=total_count,
|
|
||||||
)
|
|
||||||
return await make_response(html + mini_html, 200)
|
return await make_response(html + mini_html, 200)
|
||||||
|
|
||||||
@bp.get("/add/")
|
@bp.get("/add/")
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ Routes:
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from quart import Blueprint, g, request, render_template, render_template_string, make_response
|
from quart import Blueprint, g, request, render_template, make_response
|
||||||
|
|
||||||
from shared.browser.app.utils.htmx import is_htmx_request
|
from shared.browser.app.utils.htmx import is_htmx_request
|
||||||
from shared.infrastructure.cart_identity import current_cart_identity
|
from shared.infrastructure.cart_identity import current_cart_identity
|
||||||
from shared.infrastructure.data_client import fetch_data
|
|
||||||
from shared.contracts.dtos import CartSummaryDTO, dto_from_dict
|
|
||||||
from shared.services.registry import services
|
from shared.services.registry import services
|
||||||
|
|
||||||
|
|
||||||
@@ -108,28 +106,21 @@ def register() -> Blueprint:
|
|||||||
# Load entry DTO for the widget template
|
# Load entry DTO for the widget template
|
||||||
entry = await services.calendar.entry_by_id(g.s, entry_id)
|
entry = await services.calendar.entry_by_id(g.s, entry_id)
|
||||||
|
|
||||||
# Updated cart count for OOB mini-cart
|
# Fetch OOB cart-mini fragment from cart service
|
||||||
summary_params = {}
|
from shared.infrastructure.fragments import fetch_fragment
|
||||||
|
frag_params = {"oob": "1"}
|
||||||
if ident["user_id"] is not None:
|
if ident["user_id"] is not None:
|
||||||
summary_params["user_id"] = ident["user_id"]
|
frag_params["user_id"] = str(ident["user_id"])
|
||||||
if ident["session_id"] is not None:
|
if ident["session_id"] is not None:
|
||||||
summary_params["session_id"] = ident["session_id"]
|
frag_params["session_id"] = ident["session_id"]
|
||||||
raw_summary = await fetch_data("cart", "cart-summary", params=summary_params, required=False)
|
|
||||||
summary = dto_from_dict(CartSummaryDTO, raw_summary) if raw_summary else CartSummaryDTO()
|
|
||||||
cart_count = summary.count + summary.calendar_count + summary.ticket_count
|
|
||||||
|
|
||||||
# Render widget + OOB cart-mini
|
|
||||||
widget_html = await render_template(
|
widget_html = await render_template(
|
||||||
"_types/page_summary/_ticket_widget.html",
|
"_types/page_summary/_ticket_widget.html",
|
||||||
entry=entry,
|
entry=entry,
|
||||||
qty=qty,
|
qty=qty,
|
||||||
ticket_url=f"/{g.post_slug}/tickets/adjust",
|
ticket_url=f"/{g.post_slug}/tickets/adjust",
|
||||||
)
|
)
|
||||||
mini_html = await render_template_string(
|
mini_html = await fetch_fragment("cart", "cart-mini", params=frag_params, required=False)
|
||||||
'{% from "_types/cart/_mini.html" import mini with context %}'
|
|
||||||
'{{ mini(oob="true") }}',
|
|
||||||
cart_count=cart_count,
|
|
||||||
)
|
|
||||||
return await make_response(widget_html + mini_html, 200)
|
return await make_response(widget_html + mini_html, 200)
|
||||||
|
|
||||||
return bp
|
return bp
|
||||||
|
|||||||
Reference in New Issue
Block a user