Replace shared _added.html with market-owned version using cart-mini fragment
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 53s

The shared _added.html imported _types/cart/_cart.html which only
exists in the cart app. Market now has its own _added.html that:
- Fetches cart-mini fragment for the OOB mini cart update
- Uses market's own _types/product/_cart.html macros
- Drops cart summary/show_cart (not visible on product pages)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-24 10:49:09 +00:00
parent d92d4840ed
commit 06e700820e
2 changed files with 27 additions and 7 deletions

View File

@@ -252,19 +252,23 @@ def register():
# no explicit commit; your session middleware should handle it # no explicit commit; your session middleware should handle it
# htmx support (optional) # htmx response: OOB-swap mini cart + product buttons
if request.headers.get("HX-Request") == "true": if request.headers.get("HX-Request") == "true":
# You can return a small fragment or mini-cart here from shared.infrastructure.fragments import fetch_fragment
from shared.infrastructure.cart_identity import current_cart_identity as _ci
frag_ident = _ci()
cart_params = {}
if frag_ident["user_id"] is not None:
cart_params["user_id"] = frag_ident["user_id"]
if frag_ident["session_id"] is not None:
cart_params["session_id"] = frag_ident["session_id"]
cart_mini_html = await fetch_fragment("cart", "cart-mini", params=cart_params)
return await render_template( return await render_template(
"_types/product/_added.html", "_types/product/_added.html",
cart_mini_html=cart_mini_html,
cart=g.cart, cart=g.cart,
item=ci, item=ci,
total=total,
cart_count=sum(i.quantity for i in g.cart),
cart_total=total(g.cart),
calendar_total=lambda entries: 0,
calendar_cart_entries=[],
) )
# normal POST: go to cart page # normal POST: go to cart page

View File

@@ -0,0 +1,16 @@
{# HTMX response after add-to-cart: OOB-swap the mini cart + product buttons #}
{% import '_types/product/_cart.html' as _cart %}
{# 1. Update mini cart via cart-mini fragment #}
{{ cart_mini_html | safe }}
{# 2. Update add/remove buttons on the product #}
{{ _cart.add(d.slug, cart, oob='true') }}
{# 3. Update cart item row if visible #}
{% from '_types/product/_cart.html' import cart_item with context %}
{% if item and item.quantity > 0 %}
{{ cart_item(oob='true') }}
{% elif item %}
{{ cart_item(oob='delete') }}
{% endif %}