Skip to content

Commit e2ec212

Browse files
committed
feat: Move currency, timezone & units from config to admin settings
1 parent 7009e7c commit e2ec212

23 files changed

Lines changed: 265 additions & 85 deletions

File tree

packages/evershop/src/bin/install/templates/config.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"shop": {
3-
"currency": "USD",
43
"language": "en",
5-
"weightUnit": "kg",
6-
"dimensionUnit": "cm",
74
"timezone": "UTC"
85
},
96
"system": {

packages/evershop/src/lib/locale/timezones.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ export interface Timezone {
44
}
55

66
export const timezones: Timezone[] = [
7+
// UTC first: it's the default `shop.timezone`, so the Store Settings timezone
8+
// picker must offer it as a selectable option (otherwise the field renders blank
9+
// on a fresh store). Valid IANA zone, accepted by Luxon and Postgres alike.
10+
{
11+
code: 'UTC',
12+
name: 'Coordinated Universal Time (UTC)'
13+
},
714
{
815
code: 'Australia/Darwin',
916
name: 'AUS Central Standard Time (Australia/Darwin)'

packages/evershop/src/lib/mail/emailHelper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Handlebars from 'handlebars';
22
import {
33
getSetting,
4+
getStoreCurrency,
45
getStoreLanguage
56
} from '../../modules/setting/services/setting.js';
67
import { countries } from '../locale/countries.js';
@@ -42,7 +43,7 @@ Handlebars.registerHelper('currency', function (value) {
4243

4344
return new Intl.NumberFormat(locale, {
4445
style: 'currency',
45-
currency: getConfig('shop.currency', 'USD'),
46+
currency: getStoreCurrency(),
4647
minimumFractionDigits: 0,
4748
maximumFractionDigits: 2
4849
}).format(number);

packages/evershop/src/lib/metafield/compileField.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getConfig } from '../util/getConfig.js';
1+
import { getStoreCurrency } from '../../modules/setting/services/setting.js';
22
import { MAX_DEPTH } from './types.js';
33
import type { FieldDescriptor, Validation } from './types.js';
44

@@ -50,8 +50,8 @@ function compileScalar(field: FieldDescriptor): JSONSchema {
5050
case 'boolean':
5151
return { type: 'boolean' };
5252
case 'money': {
53-
// currency must match the store currency (spec §3.6)
54-
const currency = getConfig('shop.currency', '');
53+
// currency must match the store currency (spec §3.6) — admin setting, legacy config fallback
54+
const currency = getStoreCurrency();
5555
return {
5656
type: 'object',
5757
properties: {

packages/evershop/src/lib/util/getConfig.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ type ConfigStructure = {
44
shop: {
55
language: string;
66
timezone: string;
7-
currency: string;
8-
weightUnit: string;
9-
/** Unit for package dimensions: 'cm' | 'mm' | 'in' (default 'cm'). */
10-
dimensionUnit: string;
117
homeUrl: string;
8+
// NOTE: `currency`, `weightUnit` and `dimensionUnit` are intentionally absent — they are
9+
// admin settings now (the `setting` table), read via getStoreCurrency / getWeightUnit /
10+
// getDimensionUnit in modules/setting/services; config.json is only a legacy fallback, read
11+
// untyped there (getLegacyConfig). `timezone` and `language` stay typed because they are
12+
// still read directly/operationally — `shop.timezone` sets the DB session in connection.ts
13+
// (before any query, so it can't be a DB setting), and `shop.language` is the locale system's
14+
// synchronous fallback across translate/render/formatters.
1215
};
1316
system: {
1417
file_storage: string;

packages/evershop/src/modules/base/bootstrap.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ export default async () => {
2121
type: 'string',
2222
format: 'uri'
2323
},
24-
weightUnit: {
25-
type: 'string'
26-
},
27-
currency: {
28-
type: 'string'
29-
},
3024
language: {
3125
type: 'string'
3226
},

packages/evershop/src/modules/base/graphql/types/DateTime/DateTime.resolvers.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { DateTime } from 'luxon';
22
import { getConfig } from '../../../../../lib/util/getConfig.js';
3+
import { getStoreTimezone } from '../../../../setting/services/setting.js';
34

45
export default {
56
DateTime: {
67
value: (dateTime) => dateTime,
7-
timezone: async () => {
8-
const timeZone = getConfig('shop.timezone', 'UTC');
9-
return timeZone;
10-
},
11-
text: async (value, { format = 'yyyy-LL-dd' }) => {
8+
// Display timezone (admin setting `storeTimeZone`), falling back to the operational
9+
// `shop.timezone` config when unset. NOT the DB-session timezone.
10+
timezone: () => getStoreTimezone(),
11+
text: (value, { format = 'yyyy-LL-dd' }) => {
1212
if (!DateTime.fromJSDate(value).isValid) {
1313
return null;
1414
}
15-
const timeZone = getConfig('shop.timezone', 'UTC');
15+
const timeZone = getStoreTimezone();
1616
const language = getConfig('shop.language', 'en');
1717
const date = DateTime.fromJSDate(value, { zone: timeZone })
1818
.setLocale(language)

packages/evershop/src/modules/checkout/api/createCart/createNewCart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { select } from '@evershop/postgres-query-builder';
22
import { translate } from '../../../../lib/locale/translate/translate.js';
33
import { pool } from '../../../../lib/postgres/connection.js';
4-
import { getConfig } from '../../../../lib/util/getConfig.js';
54
import {
65
INVALID_PAYLOAD,
76
INTERNAL_SERVER_ERROR,
87
OK
98
} from '../../../../lib/util/httpStatus.js';
109
import { setContextValue } from '../../../graphql/services/contextHelper.js';
10+
import { getStoreCurrency } from '../../../setting/services/setting.js';
1111
import { Cart } from '../../services/cart/Cart.js';
1212
import { saveCart } from '../../services/saveCart.js';
1313

1414
export default async (request, response, next) => {
1515
try {
1616
const { items, customer_full_name, customer_email } = request.body;
1717
const cartData = {
18-
currency: getConfig('shop.currency', 'USD')
18+
currency: getStoreCurrency()
1919
};
2020
if (customer_full_name) {
2121
cartData.customer_full_name = customer_full_name;

packages/evershop/src/modules/checkout/bootstrap.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,10 @@ export default () => {
7474
type: 'boolean'
7575
}
7676
}
77-
},
78-
shop: {
79-
type: 'object',
80-
properties: {
81-
// Unit for package dimensions (`package` table, cart/order item
82-
// snapshots). Pinned to the `Dimensions.unit` vocabulary in
83-
// oms/types/carrier.ts so no mapping layer is needed. Same model
84-
// as shop.weightUnit: store-wide, values reinterpreted (not
85-
// converted) if changed after data exists.
86-
dimensionUnit: {
87-
type: 'string',
88-
enum: ['cm', 'mm', 'in']
89-
}
90-
}
9177
}
78+
// `shop.dimensionUnit` used to be declared here. It is an admin setting now
79+
// (read via getDimensionUnit in modules/setting/services); config.json keeps
80+
// working as an untyped legacy fallback, so no schema entry is needed.
9281
}
9382
});
9483
return schema;

packages/evershop/src/modules/checkout/graphql/types/Dimension/Dimension.resolvers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { getConfig } from '../../../../../lib/util/getConfig.js';
1+
import { getDimensionUnit } from '../../../../setting/services/setting.js';
22

33
export default {
44
Dimension: {
55
value: (raw) => parseFloat(raw),
6-
unit: () => getConfig('shop.dimensionUnit', 'cm'),
6+
unit: () => getDimensionUnit(),
77
text: (raw) => {
88
const value = parseFloat(raw);
9-
const unit = getConfig('shop.dimensionUnit', 'cm');
9+
const unit = getDimensionUnit();
1010
return `${value} ${unit}`;
1111
}
1212
},

0 commit comments

Comments
 (0)