fix(loyalty): translate category names in transaction history
Some checks failed
Some checks failed
Category names in transaction tables now resolve to the current page language instead of always showing English. Updated: - category_service.validate_category_for_store: accepts lang param, uses get_translated_name() - Store transactions list route: passes request.state.language - Card detail transactions route: passes request.state.language - card_service.get_customer_transactions_with_store_names: accepts lang param for storefront route Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -807,6 +807,7 @@ class CardService:
|
||||
*,
|
||||
skip: int = 0,
|
||||
limit: int = 20,
|
||||
lang: str = "en",
|
||||
) -> tuple[list[dict], int]:
|
||||
"""
|
||||
Get transaction history for a card with store names resolved.
|
||||
@@ -853,7 +854,7 @@ class CardService:
|
||||
names = []
|
||||
for cid in tx.category_ids:
|
||||
name = category_service.validate_category_for_store(
|
||||
db, cid, tx.store_id or 0
|
||||
db, cid, tx.store_id or 0, lang=lang
|
||||
)
|
||||
if name:
|
||||
names.append(name)
|
||||
|
||||
@@ -138,11 +138,11 @@ class CategoryService:
|
||||
logger.info(f"Deleted category {category_id} from store {store_id}")
|
||||
|
||||
def validate_category_for_store(
|
||||
self, db: Session, category_id: int, store_id: int
|
||||
self, db: Session, category_id: int, store_id: int, lang: str = "en"
|
||||
) -> str | None:
|
||||
"""Validate that a category belongs to the store.
|
||||
|
||||
Returns the category name if valid, None if not found.
|
||||
Returns the translated category name if valid, None if not found.
|
||||
"""
|
||||
category = (
|
||||
db.query(StoreTransactionCategory)
|
||||
@@ -153,7 +153,9 @@ class CategoryService:
|
||||
)
|
||||
.first()
|
||||
)
|
||||
return category.name if category else None
|
||||
if not category:
|
||||
return None
|
||||
return category.get_translated_name(lang)
|
||||
|
||||
|
||||
# Singleton
|
||||
|
||||
Reference in New Issue
Block a user