diff --git a/bp/post/routes.py b/bp/post/routes.py index fd8a07f..42aa130 100644 --- a/bp/post/routes.py +++ b/bp/post/routes.py @@ -65,6 +65,7 @@ def register(): p_data = getattr(g, "post_data", None) if p_data: from .services.entry_associations import get_associated_entries + from shared.internal_api import get as api_get db_post_id = (g.post_data.get("post") or {}).get("id") # <-- integer calendars = ( @@ -86,13 +87,30 @@ def register(): # Fetch associated entries for nav display associated_entries = await get_associated_entries(g.s, db_post_id) - return { + ctx = { **p_data, "base_title": f"{config()['title']} {p_data['post']['title']}", "calendars": calendars, "markets": markets, "associated_entries": associated_entries, } + + # Page cart badge: fetch page-scoped cart count for pages + post_dict = p_data.get("post") or {} + if post_dict.get("is_page"): + page_cart = await api_get( + "cart", + f"/internal/cart/summary?page_slug={post_dict['slug']}", + forward_session=True, + ) + if page_cart: + ctx["page_cart_count"] = page_cart.get("count", 0) + page_cart.get("calendar_count", 0) + ctx["page_cart_total"] = page_cart.get("total", 0) + page_cart.get("calendar_total", 0) + else: + ctx["page_cart_count"] = 0 + ctx["page_cart_total"] = 0 + + return ctx else: return {} diff --git a/templates/_types/post/header/_header.html b/templates/_types/post/header/_header.html index 16bdf45..143e79d 100644 --- a/templates/_types/post/header/_header.html +++ b/templates/_types/post/header/_header.html @@ -12,7 +12,16 @@ {{ post.title | truncate(160, True, '…') }} {% endcall %} - {% call links.desktop_nav() %} + {% call links.desktop_nav() %} + {% if page_cart_count is defined and page_cart_count > 0 %} + + + {{ page_cart_count }} + + {% endif %} {% include '_types/post/_nav.html' %} {% endcall %} {% endcall %}