From 567888c9e07954f04859e06b04b073b2844d7b88 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 24 Feb 2026 20:48:23 +0000 Subject: [PATCH] Fix cart template cross-app url_for crash and favicon 404 - Cart _cart.html: replace url_for('market.browse.product...') with market_product_url() for links and cart_global.update_quantity for quantity forms (market endpoints don't exist in cart app) - Factory favicon route: use STATIC_DIR instead of relative "static" (resolves to shared/static/ where favicon.ico actually lives) - Cart context processor: fetch all 3 fragments (cart-mini, auth-menu, nav-tree) concurrently, matching pattern in all other apps Co-Authored-By: Claude Opus 4.6 --- cart/app.py | 25 +++++++++++++++++++----- cart/templates/_types/product/_cart.html | 19 +++++++++--------- shared/infrastructure/factory.py | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/cart/app.py b/cart/app.py index dad13cd..3f041b2 100644 --- a/cart/app.py +++ b/cart/app.py @@ -52,17 +52,32 @@ async def cart_context() -> dict: """ from shared.infrastructure.context import base_context from shared.services.navigation import get_navigation_tree - from shared.infrastructure.fragments import fetch_fragment + from shared.infrastructure.cart_identity import current_cart_identity + from shared.infrastructure.fragments import fetch_fragments ctx = await base_context() - ctx["nav_tree_html"] = await fetch_fragment( - "blog", "nav-tree", - params={"app_name": "cart", "path": request.path}, - ) # Fallback for _nav.html when nav-tree fragment fetch fails ctx["menu_items"] = await get_navigation_tree(g.s) + # Pre-fetch cross-app HTML fragments concurrently + user = getattr(g, "user", None) + ident = current_cart_identity() + cart_params = {} + if ident["user_id"] is not None: + cart_params["user_id"] = ident["user_id"] + if ident["session_id"] is not None: + cart_params["session_id"] = ident["session_id"] + + cart_mini_html, auth_menu_html, nav_tree_html = await fetch_fragments([ + ("cart", "cart-mini", cart_params or None), + ("account", "auth-menu", {"email": user.email} if user else None), + ("blog", "nav-tree", {"app_name": "cart", "path": request.path}), + ]) + ctx["cart_mini_html"] = cart_mini_html + ctx["auth_menu_html"] = auth_menu_html + ctx["nav_tree_html"] = nav_tree_html + # Cart app owns cart data — use g.cart from _load_cart all_cart = getattr(g, "cart", None) or [] all_cal = await get_calendar_cart_entries(g.s) diff --git a/cart/templates/_types/product/_cart.html b/cart/templates/_types/product/_cart.html index 2c68284..d8ce3e1 100644 --- a/cart/templates/_types/product/_cart.html +++ b/cart/templates/_types/product/_cart.html @@ -130,7 +130,7 @@ class="w-24 h-24 sm:w-32 sm:h-28 rounded-xl border border-dashed border-stone-300 flex items-center justify-center text-xs text-stone-400" > No image - 'market', 'product', p.slug + {% endif %} @@ -139,7 +139,7 @@

- {% set href=url_for('market.browse.product.product_detail', product_slug=p.slug) %} + {% set href=market_product_url(p.slug) %}
Quantity + {% set qty_url = url_for('cart_global.update_quantity', product_id=p.id) %}