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 {}
|
||||
|
||||
|
||||
@@ -12,7 +12,16 @@
|
||||
{{ post.title | truncate(160, True, '…') }}
|
||||
</span>
|
||||
{% endcall %}
|
||||
{% call links.desktop_nav() %}
|
||||
{% call links.desktop_nav() %}
|
||||
{% if page_cart_count is defined and page_cart_count > 0 %}
|
||||
<a
|
||||
href="{{ cart_url('/' + post.slug + '/') }}"
|
||||
class="relative inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-full border border-emerald-300 bg-emerald-50 text-emerald-800 hover:bg-emerald-100 transition"
|
||||
>
|
||||
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
|
||||
<span>{{ page_cart_count }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% include '_types/post/_nav.html' %}
|
||||
{% endcall %}
|
||||
{% endcall %}
|
||||
|
||||
Reference in New Issue
Block a user