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>
83 lines
2.2 KiB
Python
83 lines
2.2 KiB
Python
# app/modules/orders/services/order_widgets.py
|
|
"""
|
|
Orders dashboard widget provider.
|
|
|
|
Provides storefront dashboard cards for order-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 OrderWidgetProvider:
|
|
"""Widget provider for orders module."""
|
|
|
|
@property
|
|
def widgets_category(self) -> str:
|
|
return "orders"
|
|
|
|
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 Orders card for the customer dashboard."""
|
|
from app.modules.orders.models.customer_order_stats import CustomerOrderStats
|
|
from app.utils.i18n import translate
|
|
|
|
stats = (
|
|
db.query(CustomerOrderStats)
|
|
.filter(
|
|
CustomerOrderStats.store_id == store_id,
|
|
CustomerOrderStats.customer_id == customer_id,
|
|
)
|
|
.first()
|
|
)
|
|
|
|
total_orders = stats.total_orders if stats else 0
|
|
lang = context.language if context else None
|
|
|
|
return [
|
|
StorefrontDashboardCard(
|
|
key="orders.summary",
|
|
icon="shopping-bag",
|
|
title=translate("orders.widget.summary.title", lang),
|
|
subtitle=translate("orders.widget.summary.subtitle", lang),
|
|
route="account/orders",
|
|
value=total_orders,
|
|
value_label=translate("orders.widget.summary.value_label", lang),
|
|
order=10,
|
|
),
|
|
]
|
|
|
|
|
|
order_widget_provider = OrderWidgetProvider()
|