Fix cart icon vanishing on add-to-cart when fragment fetch fails
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m4s

When the cart-mini fragment fetch returns empty, the HTMX outerHTML
swap was replacing #cart-mini with nothing. Now falls back to the
local _mini.html macro with count from g.cart.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-24 12:52:19 +00:00
parent 49a4780efe
commit f34d35b9c4

View File

@@ -1,8 +1,13 @@
{# 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 }}
{# 1. Update mini cart via cart-mini fragment (fallback to local macro) #}
{% if cart_mini_html %}
{{ cart_mini_html | safe }}
{% else %}
{% from '_types/cart/_mini.html' import mini with context %}
{{ mini(count=cart | sum(attribute="quantity")) }}
{% endif %}
{# 2. Update add/remove buttons on the product #}
{{ _cart.add(d.slug, cart, oob='true') }}