From 1107de989b905b960bd30f18a97cd3fe0b116b32 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Mon, 23 Mar 2026 14:15:05 +0100 Subject: [PATCH] fix(loyalty): pass merchant name server-side to admin on-behalf headers Load merchant name in page route handlers and pass to template context. Headers now render as "Cards: Fashion Group S.A." using server-side Jinja2 variables instead of relying on JS program.merchant_name which was not in the ProgramResponse schema. Co-Authored-By: Claude Opus 4.6 (1M context) --- app/modules/loyalty/routes/pages/admin.py | 20 ++++++++++++++----- .../loyalty/admin/merchant-cards.html | 2 +- .../loyalty/admin/merchant-pins.html | 2 +- .../loyalty/admin/merchant-transactions.html | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/modules/loyalty/routes/pages/admin.py b/app/modules/loyalty/routes/pages/admin.py index 4844e36d..bc48b1f0 100644 --- a/app/modules/loyalty/routes/pages/admin.py +++ b/app/modules/loyalty/routes/pages/admin.py @@ -15,9 +15,15 @@ from sqlalchemy.orm import Session from app.api.deps import get_db, require_menu_access from app.modules.core.utils.page_context import get_admin_context from app.modules.enums import FrontendType -from app.modules.tenancy.models import User +from app.modules.tenancy.models import Merchant, User from app.templates_config import templates + +def _get_merchant_name(db: Session, merchant_id: int) -> str: + """Look up merchant name for page header context.""" + merchant = db.query(Merchant).filter(Merchant.id == merchant_id).first() + return merchant.name if merchant else "" + router = APIRouter() # Route configuration for module route discovery @@ -139,9 +145,10 @@ async def admin_loyalty_merchant_cards( Render merchant loyalty cards list page. Shows all loyalty cards for a specific merchant. """ + merchant_name = _get_merchant_name(db, merchant_id) return templates.TemplateResponse( "loyalty/admin/merchant-cards.html", - get_admin_context(request, db, current_user, merchant_id=merchant_id), + get_admin_context(request, db, current_user, merchant_id=merchant_id, merchant_name=merchant_name), ) @@ -161,9 +168,10 @@ async def admin_loyalty_merchant_card_detail( Render merchant loyalty card detail page. Shows detailed info for a specific loyalty card. """ + merchant_name = _get_merchant_name(db, merchant_id) return templates.TemplateResponse( "loyalty/admin/merchant-card-detail.html", - get_admin_context(request, db, current_user, merchant_id=merchant_id, card_id=card_id), + get_admin_context(request, db, current_user, merchant_id=merchant_id, card_id=card_id, merchant_name=merchant_name), ) @@ -182,9 +190,10 @@ async def admin_loyalty_merchant_transactions( Render merchant loyalty transactions list page. Shows all loyalty transactions for a specific merchant. """ + merchant_name = _get_merchant_name(db, merchant_id) return templates.TemplateResponse( "loyalty/admin/merchant-transactions.html", - get_admin_context(request, db, current_user, merchant_id=merchant_id), + get_admin_context(request, db, current_user, merchant_id=merchant_id, merchant_name=merchant_name), ) @@ -203,9 +212,10 @@ async def admin_loyalty_merchant_pins( Render merchant staff PINs page (read-only). Shows all staff PINs for a specific merchant. """ + merchant_name = _get_merchant_name(db, merchant_id) return templates.TemplateResponse( "loyalty/admin/merchant-pins.html", - get_admin_context(request, db, current_user, merchant_id=merchant_id), + get_admin_context(request, db, current_user, merchant_id=merchant_id, merchant_name=merchant_name), ) diff --git a/app/modules/loyalty/templates/loyalty/admin/merchant-cards.html b/app/modules/loyalty/templates/loyalty/admin/merchant-cards.html index cc994822..43ad88bb 100644 --- a/app/modules/loyalty/templates/loyalty/admin/merchant-cards.html +++ b/app/modules/loyalty/templates/loyalty/admin/merchant-cards.html @@ -8,7 +8,7 @@ {% block alpine_data %}adminMerchantCards(){% endblock %} {% block content %} -{% call detail_page_header("(program?.merchant_name || '') + ' — " + _('loyalty.admin.merchant_cards.title') + "'", '/admin/loyalty/merchants/' ~ merchant_id, subtitle_show='program') %} +{% call detail_page_header("'" + _('loyalty.admin.merchant_cards.title') + ": " + (merchant_name or '') + "'", '/admin/loyalty/merchants/' ~ merchant_id, subtitle_show='program') %} {{ _('loyalty.admin.merchant_cards.subtitle') }} {% endcall %} diff --git a/app/modules/loyalty/templates/loyalty/admin/merchant-pins.html b/app/modules/loyalty/templates/loyalty/admin/merchant-pins.html index c87e7b38..3965c0d9 100644 --- a/app/modules/loyalty/templates/loyalty/admin/merchant-pins.html +++ b/app/modules/loyalty/templates/loyalty/admin/merchant-pins.html @@ -8,7 +8,7 @@ {% block alpine_data %}adminMerchantPins(){% endblock %} {% block content %} -{% call detail_page_header("(program?.merchant_name || '') + ' — " + _('loyalty.admin.merchant_pins.title') + "'", '/admin/loyalty/merchants/' ~ merchant_id, subtitle_show='program') %} +{% call detail_page_header("'" + _('loyalty.admin.merchant_pins.title') + ": " + (merchant_name or '') + "'", '/admin/loyalty/merchants/' ~ merchant_id, subtitle_show='program') %} {{ _('loyalty.admin.merchant_pins.subtitle') }} {% endcall %} diff --git a/app/modules/loyalty/templates/loyalty/admin/merchant-transactions.html b/app/modules/loyalty/templates/loyalty/admin/merchant-transactions.html index cceaf419..7628e7e3 100644 --- a/app/modules/loyalty/templates/loyalty/admin/merchant-transactions.html +++ b/app/modules/loyalty/templates/loyalty/admin/merchant-transactions.html @@ -8,7 +8,7 @@ {% block alpine_data %}adminMerchantTransactions(){% endblock %} {% block content %} -{% call detail_page_header("(program?.merchant_name || '') + ' — " + _('loyalty.admin.merchant_transactions.title') + "'", '/admin/loyalty/merchants/' ~ merchant_id, subtitle_show='program') %} +{% call detail_page_header("'" + _('loyalty.admin.merchant_transactions.title') + ": " + (merchant_name or '') + "'", '/admin/loyalty/merchants/' ~ merchant_id, subtitle_show='program') %} {{ _('loyalty.admin.merchant_transactions.subtitle') }} {% endcall %}