feat: show page cart badge in blog post header (Phase 4)
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 41s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 41s
Fetches page-scoped cart count from /internal/cart/summary?page_slug= for page posts and displays a cart icon with count in the post header that links to the page cart. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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 {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user