feat: add configurable currency locale and fix vendor JS init

Currency Locale Configuration:
- Add platform-level storefront settings (locale, currency)
- Create PlatformSettingsService with resolution chain:
  vendor → AdminSetting → environment → hardcoded fallback
- Add storefront_locale nullable field to Vendor model
- Update shop routes to resolve and pass locale to templates
- Add window.SHOP_CONFIG for frontend JavaScript access
- Centralize formatPrice() in shop-layout.js using SHOP_CONFIG
- Remove local formatPrice functions from shop templates

Vendor JS Bug Fix:
- Fix vendorCode being null on all vendor pages
- Root cause: page components overriding init() without calling parent
- Add parent init call to 14 vendor JS files
- Add JS-013 architecture rule to prevent future regressions
- Validator now checks vendor JS files for parent init pattern

Files changed:
- New: app/services/platform_settings_service.py
- New: alembic/versions/s7a8b9c0d1e2_add_storefront_locale_to_vendors.py
- Modified: 14 vendor JS files, shop templates, validation scripts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-02 21:26:12 +01:00
parent d9d34ab102
commit c87bdfa129
30 changed files with 522 additions and 48 deletions

View File

@@ -219,12 +219,15 @@ function shopLayoutData() {
}, 3000);
},
// Format currency
formatPrice(price) {
return new Intl.NumberFormat('en-US', {
// Format currency using configured locale
formatPrice(amount) {
if (!amount && amount !== 0) return '';
const locale = window.SHOP_CONFIG?.locale || 'fr-LU';
const currency = window.SHOP_CONFIG?.currency || 'EUR';
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: 'USD'
}).format(price);
currency: currency
}).format(amount);
},
// Format date

View File

@@ -58,6 +58,12 @@ function vendorAnalytics() {
}
window._vendorAnalyticsInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
try {
await this.loadAllData();
} catch (error) {

View File

@@ -33,6 +33,12 @@ function vendorBilling() {
if (window._vendorBillingInitialized) return;
window._vendorBillingInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
try {
// Check URL params for success/cancel
const params = new URLSearchParams(window.location.search);

View File

@@ -44,6 +44,12 @@ function vendorContentPageEditor(pageId) {
}
window._vendorContentPageEditInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
try {
contentPageEditLog.info('=== VENDOR CONTENT PAGE EDITOR INITIALIZING ===');
contentPageEditLog.info('Page ID:', this.pageId);

View File

@@ -36,6 +36,12 @@ function vendorContentPagesManager() {
}
window._vendorContentPagesInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
await this.loadPages();
contentPagesLog.info('=== VENDOR CONTENT PAGES MANAGER INITIALIZATION COMPLETE ===');

View File

@@ -106,6 +106,12 @@ function vendorCustomers() {
}
window._vendorCustomersInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
// Load platform settings for rows per page
if (window.PlatformSettings) {
this.pagination.per_page = await window.PlatformSettings.getRowsPerPage();

View File

@@ -137,6 +137,12 @@ function vendorInventory() {
}
window._vendorInventoryInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
// Load platform settings for rows per page
if (window.PlatformSettings) {
this.pagination.per_page = await window.PlatformSettings.getRowsPerPage();

View File

@@ -65,6 +65,12 @@ function vendorMessages(initialConversationId = null) {
if (window._vendorMessagesInitialized) return;
window._vendorMessagesInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
try {
messagesLog.debug('Initializing vendor messages page');
await Promise.all([

View File

@@ -60,6 +60,12 @@ function vendorNotifications() {
}
window._vendorNotificationsInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
try {
await this.loadNotifications();
} catch (error) {

View File

@@ -62,6 +62,12 @@ function vendorOrderDetail() {
}
window._orderDetailInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
if (!this.orderId) {
this.error = 'Order ID not provided';
this.loading = false;

View File

@@ -137,6 +137,12 @@ function vendorOrders() {
}
window._vendorOrdersInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
// Load platform settings for rows per page
if (window.PlatformSettings) {
this.pagination.per_page = await window.PlatformSettings.getRowsPerPage();

View File

@@ -121,6 +121,12 @@ function vendorProducts() {
}
window._vendorProductsInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
// Load platform settings for rows per page
if (window.PlatformSettings) {
this.pagination.per_page = await window.PlatformSettings.getRowsPerPage();

View File

@@ -54,6 +54,12 @@ function vendorProfile() {
}
window._vendorProfileInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
try {
await this.loadProfile();
} catch (error) {

View File

@@ -68,6 +68,12 @@ function vendorSettings() {
}
window._vendorSettingsInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
try {
await this.loadSettings();
} catch (error) {

View File

@@ -73,6 +73,12 @@ function vendorTeam() {
}
window._vendorTeamInitialized = true;
// IMPORTANT: Call parent init first to set vendorCode from URL
const parentInit = data().init;
if (parentInit) {
await parentInit.call(this);
}
try {
await Promise.all([
this.loadMembers(),