Some checks failed
Two bugs from Test 5.1 on FR storefront dashboard: 1. Loyalty + Orders dashboard cards (`StorefrontDashboardCard.title`/ `subtitle`/`value_label`) were hardcoded English. Added `language` to `WidgetContext`; customer dashboard route passes `request.state.language` through; loyalty and orders widget providers now call `translate(..., context.language)` with new `widget.*` i18n keys × 4 locales each. 2. Customer-module locale JSON has redundant top-level `customers` wrapper, so after the module-locale loader auto-namespaces under module code `customers`, the actual key path is `customers.customers.customer_number` (matches the existing `loyalty.loyalty.wallet.apple` pattern). My earlier sweep used the single-prefix path for 8 references — fixed all to double-prefix. Both bugs were visible end-of-day yesterday after the api container recreate landed `1bade6e6`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
92 lines
2.4 KiB
Python
92 lines
2.4 KiB
Python
# app/modules/loyalty/services/loyalty_widgets.py
|
|
"""
|
|
Loyalty dashboard widget provider.
|
|
|
|
Provides storefront dashboard cards for loyalty-related data.
|
|
Implements get_storefront_dashboard_cards from DashboardWidgetProviderProtocol.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.modules.contracts.widgets import (
|
|
DashboardWidget,
|
|
StorefrontDashboardCard,
|
|
WidgetContext,
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class LoyaltyWidgetProvider:
|
|
"""Widget provider for loyalty module."""
|
|
|
|
@property
|
|
def widgets_category(self) -> str:
|
|
return "loyalty"
|
|
|
|
def get_store_widgets(
|
|
self,
|
|
db: Session,
|
|
store_id: int,
|
|
context: WidgetContext | None = None,
|
|
) -> list[DashboardWidget]:
|
|
return []
|
|
|
|
def get_platform_widgets(
|
|
self,
|
|
db: Session,
|
|
platform_id: int,
|
|
context: WidgetContext | None = None,
|
|
) -> list[DashboardWidget]:
|
|
return []
|
|
|
|
def get_storefront_dashboard_cards(
|
|
self,
|
|
db: Session,
|
|
store_id: int,
|
|
customer_id: int,
|
|
context: WidgetContext | None = None,
|
|
) -> list[StorefrontDashboardCard]:
|
|
"""Provide the Loyalty Rewards card for the customer dashboard."""
|
|
from app.modules.loyalty.models.loyalty_card import LoyaltyCard
|
|
from app.utils.i18n import translate
|
|
|
|
card = (
|
|
db.query(LoyaltyCard)
|
|
.filter(
|
|
LoyaltyCard.customer_id == customer_id,
|
|
LoyaltyCard.is_active.is_(True),
|
|
)
|
|
.first()
|
|
)
|
|
|
|
points = card.points_balance if card else None
|
|
lang = context.language if context else None
|
|
subtitle_key = (
|
|
"loyalty.widget.rewards.subtitle_member"
|
|
if card
|
|
else "loyalty.widget.rewards.subtitle_join"
|
|
)
|
|
|
|
return [
|
|
StorefrontDashboardCard(
|
|
key="loyalty.rewards",
|
|
icon="gift",
|
|
title=translate("loyalty.widget.rewards.title", lang),
|
|
subtitle=translate(subtitle_key, lang),
|
|
route="account/loyalty",
|
|
value=points,
|
|
value_label=(
|
|
translate("loyalty.widget.rewards.value_label", lang)
|
|
if points is not None
|
|
else None
|
|
),
|
|
order=30,
|
|
),
|
|
]
|
|
|
|
|
|
loyalty_widget_provider = LoyaltyWidgetProvider()
|