Render cart-mini directly in add-to-cart HTMX response
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 59s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 59s
The handler already has g.cart with the updated items — no need to make an HTTP round-trip to the cart app's fragment endpoint. Renders the _mini.html macro directly with the count from g.cart. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -254,23 +254,8 @@ def register():
|
||||
|
||||
# htmx response: OOB-swap mini cart + product buttons
|
||||
if request.headers.get("HX-Request") == "true":
|
||||
# Commit so the cart app sees the updated data when we fetch the fragment
|
||||
await g.tx.commit()
|
||||
g.tx = await g.s.begin()
|
||||
|
||||
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(
|
||||
"_types/product/_added.html",
|
||||
cart_mini_html=cart_mini_html,
|
||||
cart=g.cart,
|
||||
item=ci,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user