Add website special-products source setting for storefronts.
Let businesses choose product vs store_item sourcing, defaulting from the store module, and expose it on tenant resolve and store-specials. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
8609d8d4fd
commit
b0d4916138
@@ -20,10 +20,12 @@ import {
|
||||
HOME_CHART_IDS,
|
||||
MellatGatewaySettings,
|
||||
PAYMENT_GATEWAY_IDS,
|
||||
SPECIAL_PRODUCTS_SOURCE_IDS,
|
||||
type DashboardLocale,
|
||||
type DashboardThemeMode,
|
||||
type HomeChartId,
|
||||
type PaymentGatewayId,
|
||||
type SpecialProductsSource,
|
||||
OrderProcessStep,
|
||||
StubGatewaySettings,
|
||||
ZarinpalGatewaySettings,
|
||||
@@ -66,6 +68,27 @@ export function normalizeEnabledBusinessModules(
|
||||
return BUSINESS_MODULE_IDS.filter((id) => selected.has(id));
|
||||
}
|
||||
|
||||
export function isSpecialProductsSource(
|
||||
value: unknown,
|
||||
): value is SpecialProductsSource {
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
(SPECIAL_PRODUCTS_SOURCE_IDS as readonly string[]).includes(value)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicit saved source wins. Otherwise store businesses default to store items,
|
||||
* catalog-only businesses default to products.
|
||||
*/
|
||||
export function resolveSpecialProductsSource(
|
||||
value: unknown,
|
||||
enabledModules: readonly BusinessModuleId[],
|
||||
): SpecialProductsSource {
|
||||
if (isSpecialProductsSource(value)) return value;
|
||||
return enabledModules.includes('store') ? 'store_item' : 'product';
|
||||
}
|
||||
|
||||
export function normalizeHomeCharts(value: unknown): [HomeChartId, HomeChartId] {
|
||||
if (!Array.isArray(value)) {
|
||||
return [...DEFAULT_HOME_CHARTS];
|
||||
@@ -343,7 +366,13 @@ export function normalizeBusinessSettings(raw: unknown): BusinessSettings {
|
||||
: {};
|
||||
const store = isRecord(source.store) ? source.store : {};
|
||||
const modules = isRecord(source.modules) ? source.modules : {};
|
||||
const website = isRecord(source.website) ? source.website : {};
|
||||
const hasModulesKey = Object.prototype.hasOwnProperty.call(source, 'modules');
|
||||
const enabledModules = hasModulesKey
|
||||
? Array.isArray(modules.enabled)
|
||||
? normalizeEnabledBusinessModules(modules.enabled)
|
||||
: []
|
||||
: [...DEFAULT_ENABLED_BUSINESS_MODULES];
|
||||
|
||||
return {
|
||||
branding: {
|
||||
@@ -375,13 +404,15 @@ export function normalizeBusinessSettings(raw: unknown): BusinessSettings {
|
||||
},
|
||||
modules: {
|
||||
// Missing `modules` → all enabled (legacy). Explicit `{ enabled: [] }` stays empty.
|
||||
enabled: hasModulesKey
|
||||
? Array.isArray(modules.enabled)
|
||||
? normalizeEnabledBusinessModules(modules.enabled)
|
||||
: []
|
||||
: [...DEFAULT_ENABLED_BUSINESS_MODULES],
|
||||
enabled: enabledModules,
|
||||
charts: normalizeHomeCharts(modules.charts),
|
||||
},
|
||||
website: {
|
||||
specialProductsSource: resolveSpecialProductsSource(
|
||||
website.specialProductsSource,
|
||||
enabledModules,
|
||||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -423,6 +454,11 @@ export function mergeBusinessSettings(
|
||||
enabled: patch.modules?.enabled ?? current.modules.enabled,
|
||||
charts: patch.modules?.charts ?? current.modules.charts,
|
||||
},
|
||||
website: {
|
||||
specialProductsSource:
|
||||
patch.website?.specialProductsSource ??
|
||||
current.website.specialProductsSource,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user