Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Standardize store time zones and admin locales to IANA/ISO codes (#15001)

Damian Legawiec21dc28f68623
diff --git a/.changeset/store-regional-setting-types.md b/.changeset/store-regional-setting-types.md
new file mode 100644
index 0000000000..26c4a5dc0b
--- /dev/null
+++ b/.changeset/store-regional-setting-types.md
@@ -0,0 +1,7 @@
+---
+"@spree/core": patch
+"@spree/admin-sdk": patch
+"@spree/seller-sdk": patch
+---
+
+Typed the store's regional settings. The store's `default_country_code` is now `CountryCode`, its `admin_locale` is `LocaleCode` (send `null` to clear it), and its `timezone` — also on the seller profile — is the new `TimeZone` type, which suggests common IANA time zones while accepting any other. `TIME_ZONES` in `@spree/core` lists the suggested zones.
diff --git a/.changeset/store-settings-time-zone-picker.md b/.changeset/store-settings-time-zone-picker.md
new file mode 100644
index 0000000000..16c6789f6e
--- /dev/null
+++ b/.changeset/store-settings-time-zone-picker.md
@@ -0,0 +1,5 @@
+---
+"@spree/dashboard": patch
+---
+
+Fixed Store Settings so the time zone picker always shows the store's saved zone, and choosing "Use the default language" clears the store's admin language instead of keeping the previous one.
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yaml
index 6d1e374946..a4a5a18efb 100644
--- a/docs/api-reference/admin.yaml
+++ b/docs/api-reference/admin.yaml
@@ -73350,6 +73350,247 @@ components:
default_country_code:
type: string
nullable: true
+ enum:
+ - AD
+ - AE
+ - AF
+ - AG
+ - AI
+ - AL
+ - AM
+ - AO
+ - AR
+ - AS
+ - AT
+ - AU
+ - AW
+ - AZ
+ - BA
+ - BB
+ - BD
+ - BE
+ - BF
+ - BG
+ - BH
+ - BI
+ - BJ
+ - BL
+ - BM
+ - BN
+ - BO
+ - BQ
+ - BR
+ - BS
+ - BT
+ - BW
+ - BY
+ - BZ
+ - CA
+ - CC
+ - CD
+ - CF
+ - CG
+ - CH
+ - CI
+ - CK
+ - CL
+ - CM
+ - CN
+ - CO
+ - CR
+ - CU
+ - CV
+ - CW
+ - CX
+ - CY
+ - CZ
+ - DE
+ - DJ
+ - DK
+ - DM
+ - DO
+ - DZ
+ - EC
+ - EE
+ - EG
+ - ER
+ - ES
+ - ET
+ - FI
+ - FJ
+ - FK
+ - FM
+ - FO
+ - FR
+ - GA
+ - GB
+ - GD
+ - GE
+ - GF
+ - GG
+ - GH
+ - GI
+ - GL
+ - GM
+ - GN
+ - GP
+ - GQ
+ - GR
+ - GT
+ - GU
+ - GW
+ - GY
+ - HK
+ - HN
+ - HR
+ - HT
+ - HU
+ - ID
+ - IE
+ - IL
+ - IM
+ - IN
+ - IQ
+ - IR
+ - IS
+ - IT
+ - JE
+ - JM
+ - JO
+ - JP
+ - KE
+ - KG
+ - KH
+ - KI
+ - KM
+ - KN
+ - KP
+ - KR
+ - KW
+ - KY
+ - KZ
+ - LA
+ - LB
+ - LC
+ - LI
+ - LK
+ - LR
+ - LS
+ - LT
+ - LU
+ - LV
+ - LY
+ - MA
+ - MC
+ - MD
+ - ME
+ - MF
+ - MG
+ - MH
+ - MK
+ - ML
+ - MM
+ - MN
+ - MO
+ - MP
+ - MQ
+ - MR
+ - MS
+ - MT
+ - MU
+ - MV
+ - MW
+ - MX
+ - MY
+ - MZ
+ - NA
+ - NC
+ - NE
+ - NF
+ - NG
+ - NI
+ - NL
+ - 'NO'
+ - NP
+ - NR
+ - NU
+ - NZ
+ - OM
+ - PA
+ - PE
+ - PF
+ - PG
+ - PH
+ - PK
+ - PL
+ - PM
+ - PN
+ - PR
+ - PS
+ - PT
+ - PW
+ - PY
+ - QA
+ - RE
+ - RO
+ - RS
+ - RU
+ - RW
+ - SA
+ - SB
+ - SC
+ - SD
+ - SE
+ - SG
+ - SH
+ - SI
+ - SJ
+ - SK
+ - SL
+ - SM
+ - SN
+ - SO
+ - SR
+ - SS
+ - ST
+ - SV
+ - SX
+ - SY
+ - SZ
+ - TC
+ - TD
+ - TG
+ - TH
+ - TJ
+ - TK
+ - TL
+ - TM
+ - TN
+ - TO
+ - TR
+ - TT
+ - TV
+ - TW
+ - TZ
+ - UA
+ - UG
+ - US
+ - UY
+ - UZ
+ - VA
+ - VC
+ - VE
+ - VG
+ - VI
+ - VN
+ - VU
+ - WF
+ - WS
+ - YE
+ - YT
+ - ZA
+ - ZM
+ - ZW
mail_from_address:
type: string
nullable: true
@@ -73375,8 +73616,353 @@ components:
admin_locale:
type: string
nullable: true
+ enum:
+ - aa
+ - ab
+ - ae
+ - af
+ - ak
+ - am
+ - an
+ - ar
+ - as
+ - av
+ - ay
+ - az
+ - ba
+ - be
+ - bg
+ - bh
+ - bi
+ - bm
+ - bn
+ - bo
+ - br
+ - bs
+ - ca
+ - ce
+ - ch
+ - co
+ - cr
+ - cs
+ - cu
+ - cv
+ - cy
+ - da
+ - de
+ - de-AT
+ - de-CH
+ - dv
+ - dz
+ - ee
+ - el
+ - en
+ - en-AU
+ - en-CA
+ - en-GB
+ - en-IN
+ - en-NZ
+ - en-US
+ - eo
+ - es
+ - es-419
+ - es-CL
+ - es-EC
+ - es-MX
+ - et
+ - eu
+ - fa
+ - ff
+ - fi
+ - fj
+ - fo
+ - fr
+ - fr-CA
+ - fy
+ - ga
+ - gd
+ - gl
+ - gn
+ - gu
+ - gv
+ - ha
+ - he
+ - hi
+ - ho
+ - hr
+ - ht
+ - hu
+ - hy
+ - hz
+ - ia
+ - id
+ - ie
+ - ig
+ - ii
+ - ik
+ - io
+ - is
+ - it
+ - iu
+ - ja
+ - jv
+ - ka
+ - kg
+ - ki
+ - kj
+ - kk
+ - kl
+ - km
+ - kn
+ - ko
+ - kr
+ - ks
+ - ku
+ - kv
+ - kw
+ - ky
+ - la
+ - lb
+ - lg
+ - li
+ - ln
+ - lo
+ - lt
+ - lu
+ - lv
+ - mg
+ - mh
+ - mi
+ - mk
+ - ml
+ - mn
+ - mr
+ - ms
+ - mt
+ - my
+ - na
+ - nb
+ - nd
+ - ne
+ - ng
+ - nl
+ - nn
+ - 'no'
+ - nr
+ - nv
+ - ny
+ - oc
+ - oj
+ - om
+ - or
+ - os
+ - pa
+ - pi
+ - pl
+ - ps
+ - pt
+ - pt-BR
+ - pt-PT
+ - qu
+ - rm
+ - rn
+ - ro
+ - ru
+ - rw
+ - sa
+ - sc
+ - sd
+ - se
+ - sg
+ - si
+ - sk
+ - sl
+ - sl-SI
+ - sm
+ - sn
+ - so
+ - sq
+ - sr
+ - ss
+ - st
+ - su
+ - sv
+ - sw
+ - ta
+ - te
+ - tg
+ - th
+ - ti
+ - tk
+ - tl
+ - tn
+ - to
+ - tr
+ - ts
+ - tt
+ - tw
+ - ty
+ - ug
+ - uk
+ - ur
+ - uz
+ - ve
+ - vi
+ - vo
+ - wa
+ - wo
+ - xh
+ - yi
+ - yo
+ - za
+ - zh-CN
+ - zh-HK
+ - zh-TW
+ - zu
timezone:
- type: string
+ anyOf:
+ - type: string
+ enum:
+ - Africa/Algiers
+ - Africa/Cairo
+ - Africa/Casablanca
+ - Africa/Harare
+ - Africa/Johannesburg
+ - Africa/Monrovia
+ - Africa/Nairobi
+ - America/Argentina/Buenos_Aires
+ - America/Asuncion
+ - America/Bogota
+ - America/Caracas
+ - America/Chicago
+ - America/Chihuahua
+ - America/Denver
+ - America/Guatemala
+ - America/Guyana
+ - America/Halifax
+ - America/Indiana/Indianapolis
+ - America/Juneau
+ - America/La_Paz
+ - America/Lima
+ - America/Los_Angeles
+ - America/Mazatlan
+ - America/Mexico_City
+ - America/Monterrey
+ - America/Montevideo
+ - America/New_York
+ - America/Nuuk
+ - America/Phoenix
+ - America/Puerto_Rico
+ - America/Regina
+ - America/Santiago
+ - America/Sao_Paulo
+ - America/St_Johns
+ - America/Tijuana
+ - Asia/Almaty
+ - Asia/Baghdad
+ - Asia/Baku
+ - Asia/Bangkok
+ - Asia/Chongqing
+ - Asia/Colombo
+ - Asia/Dhaka
+ - Asia/Hong_Kong
+ - Asia/Irkutsk
+ - Asia/Jakarta
+ - Asia/Jerusalem
+ - Asia/Kabul
+ - Asia/Kamchatka
+ - Asia/Karachi
+ - Asia/Kathmandu
+ - Asia/Kolkata
+ - Asia/Krasnoyarsk
+ - Asia/Kuala_Lumpur
+ - Asia/Kuwait
+ - Asia/Magadan
+ - Asia/Muscat
+ - Asia/Novosibirsk
+ - Asia/Riyadh
+ - Asia/Seoul
+ - Asia/Shanghai
+ - Asia/Singapore
+ - Asia/Srednekolymsk
+ - Asia/Taipei
+ - Asia/Tashkent
+ - Asia/Tbilisi
+ - Asia/Tehran
+ - Asia/Tokyo
+ - Asia/Ulaanbaatar
+ - Asia/Urumqi
+ - Asia/Vladivostok
+ - Asia/Yakutsk
+ - Asia/Yangon
+ - Asia/Yekaterinburg
+ - Asia/Yerevan
+ - Atlantic/Azores
+ - Atlantic/Cape_Verde
+ - Atlantic/South_Georgia
+ - Australia/Adelaide
+ - Australia/Brisbane
+ - Australia/Canberra
+ - Australia/Darwin
+ - Australia/Hobart
+ - Australia/Melbourne
+ - Australia/Perth
+ - Australia/Sydney
+ - Etc/GMT+12
+ - Europe/Amsterdam
+ - Europe/Athens
+ - Europe/Belgrade
+ - Europe/Berlin
+ - Europe/Bratislava
+ - Europe/Brussels
+ - Europe/Bucharest
+ - Europe/Budapest
+ - Europe/Copenhagen
+ - Europe/Dublin
+ - Europe/Helsinki
+ - Europe/Istanbul
+ - Europe/Kaliningrad
+ - Europe/Kyiv
+ - Europe/Lisbon
+ - Europe/Ljubljana
+ - Europe/London
+ - Europe/Madrid
+ - Europe/Minsk
+ - Europe/Moscow
+ - Europe/Paris
+ - Europe/Prague
+ - Europe/Riga
+ - Europe/Rome
+ - Europe/Samara
+ - Europe/Sarajevo
+ - Europe/Skopje
+ - Europe/Sofia
+ - Europe/Stockholm
+ - Europe/Tallinn
+ - Europe/Vienna
+ - Europe/Vilnius
+ - Europe/Volgograd
+ - Europe/Warsaw
+ - Europe/Zagreb
+ - Europe/Zurich
+ - Pacific/Apia
+ - Pacific/Auckland
+ - Pacific/Chatham
+ - Pacific/Fakaofo
+ - Pacific/Fiji
+ - Pacific/Guadalcanal
+ - Pacific/Guam
+ - Pacific/Honolulu
+ - Pacific/Majuro
+ - Pacific/Midway
+ - Pacific/Noumea
+ - Pacific/Pago_Pago
+ - Pacific/Port_Moresby
+ - Pacific/Tongatapu
+ - UTC
+ - type: string
+ description: Common IANA time zones; any other IANA time zone identifier
+ is accepted too.
storefront_url:
type: string
nullable: true
@@ -77929,6 +78515,150 @@ components:
- zh-HK
- zh-TW
- zu
+ TimeZone:
+ anyOf:
+ - type: string
+ enum:
+ - Africa/Algiers
+ - Africa/Cairo
+ - Africa/Casablanca
+ - Africa/Harare
+ - Africa/Johannesburg
+ - Africa/Monrovia
+ - Africa/Nairobi
+ - America/Argentina/Buenos_Aires
+ - America/Asuncion
+ - America/Bogota
+ - America/Caracas
+ - America/Chicago
+ - America/Chihuahua
+ - America/Denver
+ - America/Guatemala
+ - America/Guyana
+ - America/Halifax
+ - America/Indiana/Indianapolis
+ - America/Juneau
+ - America/La_Paz
+ - America/Lima
+ - America/Los_Angeles
+ - America/Mazatlan
+ - America/Mexico_City
+ - America/Monterrey
+ - America/Montevideo
+ - America/New_York
+ - America/Nuuk
+ - America/Phoenix
+ - America/Puerto_Rico
+ - America/Regina
+ - America/Santiago
+ - America/Sao_Paulo
+ - America/St_Johns
+ - America/Tijuana
+ - Asia/Almaty
+ - Asia/Baghdad
+ - Asia/Baku
+ - Asia/Bangkok
+ - Asia/Chongqing
+ - Asia/Colombo
+ - Asia/Dhaka
+ - Asia/Hong_Kong
+ - Asia/Irkutsk
+ - Asia/Jakarta
+ - Asia/Jerusalem
+ - Asia/Kabul
+ - Asia/Kamchatka
+ - Asia/Karachi
+ - Asia/Kathmandu
+ - Asia/Kolkata
+ - Asia/Krasnoyarsk
+ - Asia/Kuala_Lumpur
+ - Asia/Kuwait
+ - Asia/Magadan
+ - Asia/Muscat
+ - Asia/Novosibirsk
+ - Asia/Riyadh
+ - Asia/Seoul
+ - Asia/Shanghai
+ - Asia/Singapore
+ - Asia/Srednekolymsk
+ - Asia/Taipei
+ - Asia/Tashkent
+ - Asia/Tbilisi
+ - Asia/Tehran
+ - Asia/Tokyo
+ - Asia/Ulaanbaatar
+ - Asia/Urumqi
+ - Asia/Vladivostok
+ - Asia/Yakutsk
+ - Asia/Yangon
+ - Asia/Yekaterinburg
+ - Asia/Yerevan
+ - Atlantic/Azores
+ - Atlantic/Cape_Verde
+ - Atlantic/South_Georgia
+ - Australia/Adelaide
+ - Australia/Brisbane
+ - Australia/Canberra
+ - Australia/Darwin
+ - Australia/Hobart
+ - Australia/Melbourne
+ - Australia/Perth
+ - Australia/Sydney
+ - Etc/GMT+12
+ - Europe/Amsterdam
+ - Europe/Athens
+ - Europe/Belgrade
+ - Europe/Berlin
+ - Europe/Bratislava
+ - Europe/Brussels
+ - Europe/Bucharest
+ - Europe/Budapest
+ - Europe/Copenhagen
+ - Europe/Dublin
+ - Europe/Helsinki
+ - Europe/Istanbul
+ - Europe/Kaliningrad
+ - Europe/Kyiv
+ - Europe/Lisbon
+ - Europe/Ljubljana
+ - Europe/London
+ - Europe/Madrid
+ - Europe/Minsk
+ - Europe/Moscow
+ - Europe/Paris
+ - Europe/Prague
+ - Europe/Riga
+ - Europe/Rome
+ - Europe/Samara
+ - Europe/Sarajevo
+ - Europe/Skopje
+ - Europe/Sofia
+ - Europe/Stockholm
+ - Europe/Tallinn
+ - Europe/Vienna
+ - Europe/Vilnius
+ - Europe/Volgograd
+ - Europe/Warsaw
+ - Europe/Zagreb
+ - Europe/Zurich
+ - Pacific/Apia
+ - Pacific/Auckland
+ - Pacific/Chatham
+ - Pacific/Fakaofo
+ - Pacific/Fiji
+ - Pacific/Guadalcanal
+ - Pacific/Guam
+ - Pacific/Honolulu
+ - Pacific/Majuro
+ - Pacific/Midway
+ - Pacific/Noumea
+ - Pacific/Pago_Pago
+ - Pacific/Port_Moresby
+ - Pacific/Tongatapu
+ - UTC
+ - type: string
+ description: Common IANA time zones; any other IANA time zone identifier is
+ accepted too.
DimensionUnit:
type: string
enum:
@@ -84240,10 +84970,15 @@ components:
language.
nullable: true
admin_locale:
- type: string
+ allOf:
+ - "$ref": "#/components/schemas/LocaleCode"
+ description: The language the dashboard opens in for every staff member;
+ null lets each use their own.
example: en
+ nullable: true
timezone:
- type: string
+ allOf:
+ - "$ref": "#/components/schemas/TimeZone"
example: Europe/Berlin
weight_unit:
"$ref": "#/components/schemas/WeightUnit"
@@ -84483,6 +85218,7 @@ components:
description: A `signed_id` from `files.upload()` for the logo in transactional
emails, or null to remove it.
nullable: true
+
SupplierCreateParams:
type: object
properties:
diff --git a/docs/api-reference/seller.yaml b/docs/api-reference/seller.yaml
index 77a2e73981..225844880b 100644
--- a/docs/api-reference/seller.yaml
+++ b/docs/api-reference/seller.yaml
@@ -28472,8 +28472,150 @@ components:
items:
"$ref": "#/components/schemas/CustomField"
timezone:
- type: string
- nullable: true
+ anyOf:
+ - type: string
+ enum:
+ - Africa/Algiers
+ - Africa/Cairo
+ - Africa/Casablanca
+ - Africa/Harare
+ - Africa/Johannesburg
+ - Africa/Monrovia
+ - Africa/Nairobi
+ - America/Argentina/Buenos_Aires
+ - America/Asuncion
+ - America/Bogota
+ - America/Caracas
+ - America/Chicago
+ - America/Chihuahua
+ - America/Denver
+ - America/Guatemala
+ - America/Guyana
+ - America/Halifax
+ - America/Indiana/Indianapolis
+ - America/Juneau
+ - America/La_Paz
+ - America/Lima
+ - America/Los_Angeles
+ - America/Mazatlan
+ - America/Mexico_City
+ - America/Monterrey
+ - America/Montevideo
+ - America/New_York
+ - America/Nuuk
+ - America/Phoenix
+ - America/Puerto_Rico
+ - America/Regina
+ - America/Santiago
+ - America/Sao_Paulo
+ - America/St_Johns
+ - America/Tijuana
+ - Asia/Almaty
+ - Asia/Baghdad
+ - Asia/Baku
+ - Asia/Bangkok
+ - Asia/Chongqing
+ - Asia/Colombo
+ - Asia/Dhaka
+ - Asia/Hong_Kong
+ - Asia/Irkutsk
+ - Asia/Jakarta
+ - Asia/Jerusalem
+ - Asia/Kabul
+ - Asia/Kamchatka
+ - Asia/Karachi
+ - Asia/Kathmandu
+ - Asia/Kolkata
+ - Asia/Krasnoyarsk
+ - Asia/Kuala_Lumpur
+ - Asia/Kuwait
+ - Asia/Magadan
+ - Asia/Muscat
+ - Asia/Novosibirsk
+ - Asia/Riyadh
+ - Asia/Seoul
+ - Asia/Shanghai
+ - Asia/Singapore
+ - Asia/Srednekolymsk
+ - Asia/Taipei
+ - Asia/Tashkent
+ - Asia/Tbilisi
+ - Asia/Tehran
+ - Asia/Tokyo
+ - Asia/Ulaanbaatar
+ - Asia/Urumqi
+ - Asia/Vladivostok
+ - Asia/Yakutsk
+ - Asia/Yangon
+ - Asia/Yekaterinburg
+ - Asia/Yerevan
+ - Atlantic/Azores
+ - Atlantic/Cape_Verde
+ - Atlantic/South_Georgia
+ - Australia/Adelaide
+ - Australia/Brisbane
+ - Australia/Canberra
+ - Australia/Darwin
+ - Australia/Hobart
+ - Australia/Melbourne
+ - Australia/Perth
+ - Australia/Sydney
+ - Etc/GMT+12
+ - Europe/Amsterdam
+ - Europe/Athens
+ - Europe/Belgrade
+ - Europe/Berlin
+ - Europe/Bratislava
+ - Europe/Brussels
+ - Europe/Bucharest
+ - Europe/Budapest
+ - Europe/Copenhagen
+ - Europe/Dublin
+ - Europe/Helsinki
+ - Europe/Istanbul
+ - Europe/Kaliningrad
+ - Europe/Kyiv
+ - Europe/Lisbon
+ - Europe/Ljubljana
+ - Europe/London
+ - Europe/Madrid
+ - Europe/Minsk
+ - Europe/Moscow
+ - Europe/Paris
+ - Europe/Prague
+ - Europe/Riga
+ - Europe/Rome
+ - Europe/Samara
+ - Europe/Sarajevo
+ - Europe/Skopje
+ - Europe/Sofia
+ - Europe/Stockholm
+ - Europe/Tallinn
+ - Europe/Vienna
+ - Europe/Vilnius
+ - Europe/Volgograd
+ - Europe/Warsaw
+ - Europe/Zagreb
+ - Europe/Zurich
+ - Pacific/Apia
+ - Pacific/Auckland
+ - Pacific/Chatham
+ - Pacific/Fakaofo
+ - Pacific/Fiji
+ - Pacific/Guadalcanal
+ - Pacific/Guam
+ - Pacific/Honolulu
+ - Pacific/Majuro
+ - Pacific/Midway
+ - Pacific/Noumea
+ - Pacific/Pago_Pago
+ - Pacific/Port_Moresby
+ - Pacific/Tongatapu
+ - UTC
+ - type: string
+ nullable: true
+ description: Common IANA time zones; any other IANA time zone identifier
+ is accepted too.
status:
anyOf:
- type: string
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index 90ba58b27c..03167eeb44 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -664,6 +664,8 @@ Settings no longer reach the Admin and Seller APIs in the shape of Ruby's prefer
`order.preferred_stock_location_id` keeps its name: it is an association, not a setting. Validation errors name the field without the prefix too. The Admin and Seller APIs no longer accept the old `preferred_*` names; send the new ones. The store's `storefront_url` is the setting as saved, `null` when unset; `url` is the address customer links use. The store's `default_minimum_payout_amount` and `default_commission_tax_rate` are now exact decimal strings (`"0.23"`) instead of numbers.
+**Time zones are IANA names.** A store's `timezone` (and the seller profile's, which reads it) is always an IANA identifier such as `America/New_York` or `UTC`, typed as `TimeZone` in the SDKs. A Rails display name such as `Eastern Time (US & Canada)` sent on write is converted to its IANA name; a value that names no time zone is refused with a `422`. The store's `admin_locale` likewise only takes a locale code Spree lists (`en_US` is converted to `en-US`), and `null` clears it. The `store_regional_settings` upgrade step converts stored values, resets a time zone that names no zone to the store default, and clears an admin language Spree does not list.
+
**`preference_schema` is replaced by `schema`.** Rules, actions, payment methods and integrations no longer carry `preference_schema` on every row. Each family's `/types` endpoint (and the delivery-method and promotion-action calculator lists) returns a `schema` per type instead: the JSON Schema of its `preferences`, with `format`, `enum`, `default` and `x-spree-secret`. Read a row's type, then look up its schema there. `/payment_methods/types` now lists every provider, with `installed: true` on those the store already has, instead of leaving them out.
**Writes are validated.** A `preferences` payload with an unknown key, a value of the wrong type, a value outside the declared choices, or an id of another model or another store is refused with a `422` whose `code` is `invalid_preferences`. `details` names each failing value by its JSON pointer (`/preferences/channel_ids/1`, or `/rules/0/preferences/channel_ids/1` inside a list of rules). Before, unknown keys were silently dropped. Send decimals as strings (`"10.0"`) and record ids as prefixed ids (`ch_…`).
diff --git a/packages/admin-sdk/src/types/generated/Enums.ts b/packages/admin-sdk/src/types/generated/Enums.ts
index 076d0f6a10..a59cf9e8bb 100644
--- a/packages/admin-sdk/src/types/generated/Enums.ts
+++ b/packages/admin-sdk/src/types/generated/Enums.ts
@@ -1,4 +1,4 @@
-// Typelizer digest a291fde5935ffea3d03730e34c2f5e3a
+// Typelizer digest abf471a11c03a4220152b700b38546fb
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
export type { ActorKind } from '@spree/sdk-core';
@@ -79,5 +79,6 @@ export type { TaxIdentifierSource } from '@spree/sdk-core';
export type { TaxIdentifierValidationStatus } from '@spree/sdk-core';
export type { TaxRemittance } from '@spree/sdk-core';
export type { TaxabilityReason } from '@spree/sdk-core';
+export type { TimeZone } from '@spree/sdk-core';
export type { UnitSystem } from '@spree/sdk-core';
export type { WeightUnit } from '@spree/sdk-core';
diff --git a/packages/admin-sdk/src/types/generated/Store.ts b/packages/admin-sdk/src/types/generated/Store.ts
index c8ddac5b99..c695fed1fb 100644
--- a/packages/admin-sdk/src/types/generated/Store.ts
+++ b/packages/admin-sdk/src/types/generated/Store.ts
@@ -1,7 +1,7 @@
-// Typelizer digest bbb738f00ecbe61bcfd8eb1b1d88f384
+// Typelizer digest 6dae782db6b0e1d4c62434215d3a4178
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-import type {SetupTask, CurrencyCode, LocaleCode, WeightUnit, UnitSystem, StorefrontAccess, CaptureMethod, ProviderFailurePolicy, PayoutScheduleInterval, DocumentNumberFormat, EmailFont} from '@/types'
+import type {SetupTask, CurrencyCode, LocaleCode, CountryCode, TimeZone, WeightUnit, UnitSystem, StorefrontAccess, CaptureMethod, ProviderFailurePolicy, PayoutScheduleInterval, DocumentNumberFormat, EmailFont} from '@/types'
interface Store {
id: string;
@@ -12,7 +12,7 @@ interface Store {
code: string;
default_currency: CurrencyCode;
default_locale: LocaleCode;
- default_country_code: string | null;
+ default_country_code: CountryCode | null;
mail_from_address: string | null;
customer_support_email: string | null;
new_order_notifications_email: string | null;
@@ -22,8 +22,8 @@ interface Store {
order_routing_strategy: string;
/** Payout provider; null uses the installation default. Built-in: system. Provider gems register more (e.g. stripe). */
payout_provider: string | null;
- admin_locale: string | null;
- timezone: string;
+ admin_locale: LocaleCode | null;
+ timezone: TimeZone;
storefront_url: string | null;
weight_unit: WeightUnit;
unit_system: UnitSystem;
diff --git a/packages/admin-sdk/src/types/generated/index.ts b/packages/admin-sdk/src/types/generated/index.ts
index b1790f4a1b..a2f0b3879b 100644
--- a/packages/admin-sdk/src/types/generated/index.ts
+++ b/packages/admin-sdk/src/types/generated/index.ts
@@ -1,7 +1,7 @@
-// Typelizer digest e1f8ebdd912bdb148613bcc10ccf38e8
+// Typelizer digest 0e488b8a2eac2b6da96c7f11aac58ffb
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-export type { ActorKind, AddressOwnerType, ApiKeyType, CaptureMethod, CatalogAssignableType, CatalogPriceSource, ClaimResolution, ClaimStatus, CollectionRuleMatchPolicy, CollectionSortOrder, CommissionKind, CompanyInvitationStatus, CompanyKind, ConsentSource, CountryCode, CurrencyCode, DataRequestKind, DataRequestStatus, DeliveryStatus, DeliveryZoneMemberType, DimensionUnit, DiscountKind, DocumentNumberFormat, EmailFont, EmailTemplateKind, ExchangeStatus, FeeKind, FileUploadVisibility, FulfillmentItemStatus, FulfillmentStatus, FulfillmentType, GiftCardStatus, ImportRowStatus, ImportStatus, InvitationStatus, LocaleCode, MaintenanceTaskRunStatus, MatchPolicy, MediaType, OptionTypeKind, OrderFulfillmentStatus, OrderPaymentStatus, OrderStatus, PackageTypeKind, PaymentSourceType, PaymentStatus, PayoutScheduleInterval, PermissionKind, PickupStockPolicy, PriceListStatus, ProductStatus, ProductSubmissionStatus, ProviderFailurePolicy, PurchaseOrderStatus, PurchaseUnit, ReturnStatus, SellerPayoutStatus, SellerRequirementState, SellerRequirementSubmissionStatus, SellerStatus, SellerTransferKind, SellerTransferStatus, ShippingLabelFormat, ShippingLabelOwnerType, ShippingLabelSource, ShippingLabelStatus, StockLocationKind, StockMovementKind, StockReceiptLineType, StockReceiptReceivableType, StockReceiptRejectionReason, StockTransferStatus, StorefrontAccess, TaxExemptionCertificateStatus, TaxIdentifierSource, TaxIdentifierValidationStatus, TaxRemittance, TaxabilityReason, UnitSystem, WeightUnit } from './Enums'
+export type { ActorKind, AddressOwnerType, ApiKeyType, CaptureMethod, CatalogAssignableType, CatalogPriceSource, ClaimResolution, ClaimStatus, CollectionRuleMatchPolicy, CollectionSortOrder, CommissionKind, CompanyInvitationStatus, CompanyKind, ConsentSource, CountryCode, CurrencyCode, DataRequestKind, DataRequestStatus, DeliveryStatus, DeliveryZoneMemberType, DimensionUnit, DiscountKind, DocumentNumberFormat, EmailFont, EmailTemplateKind, ExchangeStatus, FeeKind, FileUploadVisibility, FulfillmentItemStatus, FulfillmentStatus, FulfillmentType, GiftCardStatus, ImportRowStatus, ImportStatus, InvitationStatus, LocaleCode, MaintenanceTaskRunStatus, MatchPolicy, MediaType, OptionTypeKind, OrderFulfillmentStatus, OrderPaymentStatus, OrderStatus, PackageTypeKind, PaymentSourceType, PaymentStatus, PayoutScheduleInterval, PermissionKind, PickupStockPolicy, PriceListStatus, ProductStatus, ProductSubmissionStatus, ProviderFailurePolicy, PurchaseOrderStatus, PurchaseUnit, ReturnStatus, SellerPayoutStatus, SellerRequirementState, SellerRequirementSubmissionStatus, SellerStatus, SellerTransferKind, SellerTransferStatus, ShippingLabelFormat, ShippingLabelOwnerType, ShippingLabelSource, ShippingLabelStatus, StockLocationKind, StockMovementKind, StockReceiptLineType, StockReceiptReceivableType, StockReceiptRejectionReason, StockTransferStatus, StorefrontAccess, TaxExemptionCertificateStatus, TaxIdentifierSource, TaxIdentifierValidationStatus, TaxRemittance, TaxabilityReason, TimeZone, UnitSystem, WeightUnit } from './Enums'
export type { default as Actor } from './Actor'
export type { default as AddressOwner } from './AddressOwner'
export type { default as Address } from './Address'
diff --git a/packages/admin-sdk/src/types/params/StoreUpdateParams.ts b/packages/admin-sdk/src/types/params/StoreUpdateParams.ts
index 298f248a0f..e139f64fcf 100644
--- a/packages/admin-sdk/src/types/params/StoreUpdateParams.ts
+++ b/packages/admin-sdk/src/types/params/StoreUpdateParams.ts
@@ -1,5 +1,7 @@
// This file is auto-generated from the request schemas in docs/api-reference by `pnpm generate:params`. Do not edit directly.
+import type { LocaleCode } from '../generated'
+import type { TimeZone } from '../generated'
import type { WeightUnit } from '../generated'
export type StoreUpdateParams = {
@@ -11,8 +13,9 @@ export type StoreUpdateParams = {
seo_title?: string | null
/** The storefront's default meta description, in the store's default language. */
meta_description?: string | null
- admin_locale?: string
- timezone?: string
+ /** The language the dashboard opens in for every staff member; null lets each use their own. */
+ admin_locale?: LocaleCode | null
+ timezone?: TimeZone
weight_unit?: WeightUnit
unit_system?: 'metric' | 'imperial'
/**
diff --git a/packages/core/src/enums.generated.ts b/packages/core/src/enums.generated.ts
index 40f4574d46..fb40c92916 100644
--- a/packages/core/src/enums.generated.ts
+++ b/packages/core/src/enums.generated.ts
@@ -527,6 +527,148 @@ export const TAXABILITY_REASONS = [
] as const
export type TaxabilityReason = (typeof TAXABILITY_REASONS)[number] | (string & {})
+/** Common IANA time zones; any other IANA time zone identifier is accepted too. */
+export const TIME_ZONES = [
+ 'Africa/Algiers',
+ 'Africa/Cairo',
+ 'Africa/Casablanca',
+ 'Africa/Harare',
+ 'Africa/Johannesburg',
+ 'Africa/Monrovia',
+ 'Africa/Nairobi',
+ 'America/Argentina/Buenos_Aires',
+ 'America/Asuncion',
+ 'America/Bogota',
+ 'America/Caracas',
+ 'America/Chicago',
+ 'America/Chihuahua',
+ 'America/Denver',
+ 'America/Guatemala',
+ 'America/Guyana',
+ 'America/Halifax',
+ 'America/Indiana/Indianapolis',
+ 'America/Juneau',
+ 'America/La_Paz',
+ 'America/Lima',
+ 'America/Los_Angeles',
+ 'America/Mazatlan',
+ 'America/Mexico_City',
+ 'America/Monterrey',
+ 'America/Montevideo',
+ 'America/New_York',
+ 'America/Nuuk',
+ 'America/Phoenix',
+ 'America/Puerto_Rico',
+ 'America/Regina',
+ 'America/Santiago',
+ 'America/Sao_Paulo',
+ 'America/St_Johns',
+ 'America/Tijuana',
+ 'Asia/Almaty',
+ 'Asia/Baghdad',
+ 'Asia/Baku',
+ 'Asia/Bangkok',
+ 'Asia/Chongqing',
+ 'Asia/Colombo',
+ 'Asia/Dhaka',
+ 'Asia/Hong_Kong',
+ 'Asia/Irkutsk',
+ 'Asia/Jakarta',
+ 'Asia/Jerusalem',
+ 'Asia/Kabul',
+ 'Asia/Kamchatka',
+ 'Asia/Karachi',
+ 'Asia/Kathmandu',
+ 'Asia/Kolkata',
+ 'Asia/Krasnoyarsk',
+ 'Asia/Kuala_Lumpur',
+ 'Asia/Kuwait',
+ 'Asia/Magadan',
+ 'Asia/Muscat',
+ 'Asia/Novosibirsk',
+ 'Asia/Riyadh',
+ 'Asia/Seoul',
+ 'Asia/Shanghai',
+ 'Asia/Singapore',
+ 'Asia/Srednekolymsk',
+ 'Asia/Taipei',
+ 'Asia/Tashkent',
+ 'Asia/Tbilisi',
+ 'Asia/Tehran',
+ 'Asia/Tokyo',
+ 'Asia/Ulaanbaatar',
+ 'Asia/Urumqi',
+ 'Asia/Vladivostok',
+ 'Asia/Yakutsk',
+ 'Asia/Yangon',
+ 'Asia/Yekaterinburg',
+ 'Asia/Yerevan',
+ 'Atlantic/Azores',
+ 'Atlantic/Cape_Verde',
+ 'Atlantic/South_Georgia',
+ 'Australia/Adelaide',
+ 'Australia/Brisbane',
+ 'Australia/Canberra',
+ 'Australia/Darwin',
+ 'Australia/Hobart',
+ 'Australia/Melbourne',
+ 'Australia/Perth',
+ 'Australia/Sydney',
+ 'Etc/GMT+12',
+ 'Europe/Amsterdam',
+ 'Europe/Athens',
+ 'Europe/Belgrade',
+ 'Europe/Berlin',
+ 'Europe/Bratislava',
+ 'Europe/Brussels',
+ 'Europe/Bucharest',
+ 'Europe/Budapest',
+ 'Europe/Copenhagen',
+ 'Europe/Dublin',
+ 'Europe/Helsinki',
+ 'Europe/Istanbul',
+ 'Europe/Kaliningrad',
+ 'Europe/Kyiv',
+ 'Europe/Lisbon',
+ 'Europe/Ljubljana',
+ 'Europe/London',
+ 'Europe/Madrid',
+ 'Europe/Minsk',
+ 'Europe/Moscow',
+ 'Europe/Paris',
+ 'Europe/Prague',
+ 'Europe/Riga',
+ 'Europe/Rome',
+ 'Europe/Samara',
+ 'Europe/Sarajevo',
+ 'Europe/Skopje',
+ 'Europe/Sofia',
+ 'Europe/Stockholm',
+ 'Europe/Tallinn',
+ 'Europe/Vienna',
+ 'Europe/Vilnius',
+ 'Europe/Volgograd',
+ 'Europe/Warsaw',
+ 'Europe/Zagreb',
+ 'Europe/Zurich',
+ 'Pacific/Apia',
+ 'Pacific/Auckland',
+ 'Pacific/Chatham',
+ 'Pacific/Fakaofo',
+ 'Pacific/Fiji',
+ 'Pacific/Guadalcanal',
+ 'Pacific/Guam',
+ 'Pacific/Honolulu',
+ 'Pacific/Majuro',
+ 'Pacific/Midway',
+ 'Pacific/Noumea',
+ 'Pacific/Pago_Pago',
+ 'Pacific/Port_Moresby',
+ 'Pacific/Tongatapu',
+ 'UTC',
+] as const
+export type TimeZone = (typeof TIME_ZONES)[number] | (string & {})
+
/** Every value of `UnitSystem`. */
export const UNIT_SYSTEMS = ['metric', 'imperial'] as const
export type UnitSystem = (typeof UNIT_SYSTEMS)[number]
diff --git a/packages/dashboard/e2e/store-settings.spec.ts b/packages/dashboard/e2e/store-settings.spec.ts
index c379fa4782..9d50de5f63 100644
--- a/packages/dashboard/e2e/store-settings.spec.ts
+++ b/packages/dashboard/e2e/store-settings.spec.ts
@@ -61,10 +61,8 @@ test.describe('store settings — general', () => {
// Normalize the store's admin language to English while the UI is still
// English, so the Polish selection below is always a real change regardless
- // of any value left by a prior run (the suite shares one seeded DB). A
- // concrete language (not the blank "use default") is used because clearing
- // the override sends `undefined`, which the backend treats as "unchanged".
- // Save only when this actually dirties the form.
+ // of any value left by a prior run (the suite shares one seeded DB). Save
+ // only when this actually dirties the form.
await page.goto(STORE_PATH(creds.store_id))
await expect(page.locator('#store-admin-locale')).toBeVisible({ timeout: 15_000 })
await page.locator('#store-admin-locale').click()
@@ -147,6 +145,32 @@ test.describe('store settings — general', () => {
timeout: 15_000,
})
})
+
+ // Choosing "Use the default language" removes the store's override rather
+ // than leaving the previous language in place.
+ test('clears the store admin language', async ({ page }) => {
+ const creds = await login(page)
+ await page.goto(STORE_PATH(creds.store_id))
+ const adminLocale = page.locator('#store-admin-locale')
+ const save = page.getByRole('button', { name: /^save$/i })
+ await expect(adminLocale).toBeVisible({ timeout: 15_000 })
+
+ await adminLocale.click()
+ await page.getByRole('option', { name: /^english$/i }).click()
+ if (await save.isEnabled()) {
+ await save.click()
+ await expect(save).toBeDisabled({ timeout: 15_000 })
+ }
+
+ await adminLocale.click()
+ await page.getByRole('option', { name: 'Use the default language', exact: true }).click()
+ await save.click()
+ await expect(save).toBeDisabled({ timeout: 15_000 })
+
+ await page.reload()
+ await expect(adminLocale).toContainText('Use the default language', { timeout: 15_000 })
+ })
+
// These settings are written under their plain names (`timezone`,
// `guest_checkout`, …) since preferences became a typed contract; each must
// still save and come back after a reload.
@@ -174,8 +198,10 @@ test.describe('store settings — general', () => {
),
}
+ // Browsers list this zone as `Asia/Calcutta`; the store saves and shows
+ // its current IANA name.
await timezone.click()
- await page.getByRole('option', { name: 'Europe/Warsaw', exact: true }).click()
+ await page.getByRole('option', { name: 'Asia/Kolkata', exact: true }).click()
await storefrontAccess.click()
await page.getByRole('option', { name: /^prices hidden/i }).click()
await guestCheckout.click()
@@ -188,7 +214,7 @@ test.describe('store settings — general', () => {
await page.reload()
await expect(prefix).toHaveValue('E2E', { timeout: 15_000 })
- await expect(timezone).toContainText('Europe/Warsaw')
+ await expect(timezone).toContainText('Asia/Kolkata')
await expect(storefrontAccess).toContainText(/prices hidden/i)
await expect(guestCheckout).toHaveAttribute('aria-checked', String(!original.guestCheckout))
await expect(onDispatch).toBeChecked()
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/store.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/store.tsx
index 476c7a1f8d..900c90be19 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/store.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/store.tsx
@@ -3,8 +3,11 @@ import { SpreeError, type Store, type StoreDataSourceProvider } from '@spree/adm
import {
CAPTURE_METHODS,
DOCUMENT_NUMBER_FORMATS,
+ type LocaleCode,
PROVIDER_FAILURE_POLICIES,
STOREFRONT_ACCESSES,
+ TIME_ZONES,
+ type TimeZone,
UNIT_SYSTEM_WEIGHT_UNITS,
UNIT_SYSTEMS,
type UnitSystem,
@@ -89,27 +92,19 @@ const SEO_TRANSLATABLE_FIELDS = ['seo_title', 'meta_description'] as const
const PRICING_PROVIDER_DOCS_URL = 'https://spreecommerce.org/docs/developer/providers/pim'
const INVENTORY_PROVIDER_DOCS_URL = 'https://spreecommerce.org/docs/developer/providers/erp'
-const TIMEZONES: string[] = (() => {
+// Browsers list zones under their own, sometimes older, names (`Asia/Calcutta`
+// for the `Asia/Kolkata` a store is saved with) and leave out `UTC`, the store
+// default, so Spree's suggestions are always merged in.
+const TIMEZONES: TimeZone[] = (() => {
+ let browserZones: string[] = []
try {
- // Browsers list only canonical zones, which leaves out `UTC` — the store's
- // default, and a choice a merchant must be able to return to.
- const zones = Intl.supportedValuesOf('timeZone')
- return zones.includes('UTC') ? zones : ['UTC', ...zones]
+ browserZones = Intl.supportedValuesOf('timeZone')
} catch {
- // Fallback for older browsers — a small representative set.
- return [
- 'UTC',
- 'America/New_York',
- 'America/Chicago',
- 'America/Denver',
- 'America/Los_Angeles',
- 'Europe/London',
- 'Europe/Paris',
- 'Europe/Berlin',
- 'Asia/Tokyo',
- 'Australia/Sydney',
- ]
+ // Older browsers cannot list zones; Spree's suggestions stand alone.
}
+ const zones = new Set<string>([...TIME_ZONES, ...browserZones])
+ zones.delete('UTC')
+ return ['UTC', ...[...zones].sort()]
})()
function storeToFormValues(store: Store): StoreSettingsFormValues {
@@ -253,7 +248,7 @@ function StoreSettingsForm({ store }: { store: Store }) {
name: values.name,
seo_title: values.seo_title || null,
meta_description: values.meta_description || null,
- admin_locale: values.admin_locale || undefined,
+ admin_locale: (values.admin_locale || null) as LocaleCode | null,
timezone: values.timezone,
unit_system: values.unit_system,
weight_unit: values.weight_unit,
@@ -325,9 +320,14 @@ function StoreSettingsForm({ store }: { store: Store }) {
useFormSubmitShortcut(form, onSubmit, { dirty: customFields.isDirty })
- // Compute the dynamic timezone option list once. `Intl.supportedValuesOf`
- // can be expensive on some browsers; memo keeps re-renders cheap.
- const timezoneOptions = useMemo(() => TIMEZONES.map((tz) => ({ value: tz, label: tz })), [])
+ // The saved zone stays selectable even when neither list carries its name.
+ const timezoneOptions = useMemo(
+ () =>
+ (TIMEZONES.includes(store.timezone) ? TIMEZONES : [store.timezone, ...TIMEZONES]).map(
+ (tz) => ({ value: tz, label: tz }),
+ ),
+ [store.timezone],
+ )
const unitSystemOptions = useMemo(
() => UNIT_SYSTEMS.map((value) => ({ value, label: t(`admin.store.unit_systems.${value}`) })),
[t],
diff --git a/packages/dashboard/src/schemas/store.ts b/packages/dashboard/src/schemas/store.ts
index 66798cb0d7..9a6fb6eb05 100644
--- a/packages/dashboard/src/schemas/store.ts
+++ b/packages/dashboard/src/schemas/store.ts
@@ -20,6 +20,8 @@ export const storeSettingsFormSchema = z.object({
name: z.string().min(1, { error: requiredMessage('store.name') }),
seo_title: z.string(),
meta_description: z.string(),
+ // A language the server does not list is refused there, under this field,
+ // rather than here, where a stored one would block every other setting.
admin_locale: z.string().nullable().optional(),
timezone: z.string().min(1, { error: requiredMessage('store.timezone') }),
unit_system: z.enum(UNIT_SYSTEMS),
diff --git a/packages/sdk-core/src/params-types.ts b/packages/sdk-core/src/params-types.ts
index b280317e65..e9fa75b2dc 100644
--- a/packages/sdk-core/src/params-types.ts
+++ b/packages/sdk-core/src/params-types.ts
@@ -29,13 +29,14 @@ export interface ParamsSpec {
const isRequestSchema = (name: string) => name.endsWith('Params')
// Code lists the request schemas reference by name: ISO countries and
-// currencies, Spree's locales and measurement units. The response types
+// currencies, Spree's locales, time zones and measurement units. The response types
// generated beside these files declare the same named types, so a request
// imports them from there rather than repeating them.
const SHARED_CODE_LISTS = new Set([
'CountryCode',
'CurrencyCode',
'LocaleCode',
+ 'TimeZone',
'WeightUnit',
'DimensionUnit',
])
diff --git a/packages/seller-sdk/src/types/generated/Enums.ts b/packages/seller-sdk/src/types/generated/Enums.ts
index 755711ce8d..a3e81346d1 100644
--- a/packages/seller-sdk/src/types/generated/Enums.ts
+++ b/packages/seller-sdk/src/types/generated/Enums.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 4475b95541a9751cfedeb9ea7c2b0d68
+// Typelizer digest c162286800b82cb7019990005544b798
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
export type { ClaimResolution } from '@spree/sdk-core';
@@ -34,4 +34,5 @@ export type { ShippingLabelStatus } from '@spree/sdk-core';
export type { StockLocationKind } from '@spree/sdk-core';
export type { TaxIdentifierValidationStatus } from '@spree/sdk-core';
export type { TaxRemittance } from '@spree/sdk-core';
+export type { TimeZone } from '@spree/sdk-core';
export type { WeightUnit } from '@spree/sdk-core';
diff --git a/packages/seller-sdk/src/types/generated/Profile.ts b/packages/seller-sdk/src/types/generated/Profile.ts
index c27fdc1892..11da356c44 100644
--- a/packages/seller-sdk/src/types/generated/Profile.ts
+++ b/packages/seller-sdk/src/types/generated/Profile.ts
@@ -1,7 +1,7 @@
-// Typelizer digest dbcfab2b6065b1409060327cdb88d913
+// Typelizer digest 422c95b7908c1da54d634cd4e271e26d
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-import type {CustomField, Policy, Address, SellerStatus, TaxRemittance, PayoutScheduleInterval, CurrencyCode} from '@/types'
+import type {CustomField, Policy, Address, TimeZone, SellerStatus, TaxRemittance, PayoutScheduleInterval, CurrencyCode} from '@/types'
type Profile = {
id: string;
@@ -13,7 +13,7 @@ type Profile = {
square_logo_url: string | null;
cover_photo_url: string | null;
custom_fields?: Array<CustomField>;
- timezone: string | null;
+ timezone: TimeZone | null;
status: SellerStatus;
legal_name: string | null;
registration_number: string | null;
diff --git a/packages/seller-sdk/src/types/generated/index.ts b/packages/seller-sdk/src/types/generated/index.ts
index 57ee994a41..fa42bd5d8b 100644
--- a/packages/seller-sdk/src/types/generated/index.ts
+++ b/packages/seller-sdk/src/types/generated/index.ts
@@ -1,7 +1,7 @@
-// Typelizer digest 97da2d7b7854cdc75e53cded012ea3c7
+// Typelizer digest 773e5491e3c0c7287a16eb5b7a0b5868
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-export type { ClaimResolution, ClaimStatus, CountryCode, CurrencyCode, DeliveryStatus, DimensionUnit, ExchangeStatus, FileUploadVisibility, FulfillmentStatus, ImportRowStatus, ImportStatus, InvitationStatus, MediaType, OptionTypeKind, OrderFulfillmentStatus, OrderPaymentStatus, OrderStatus, PackageTypeKind, PayoutScheduleInterval, ProductStatus, ProductSubmissionStatus, PurchaseUnit, ReturnStatus, SellerRequirementState, SellerRequirementSubmissionStatus, SellerStatus, ShippingLabelFormat, ShippingLabelOwnerType, ShippingLabelSource, ShippingLabelStatus, StockLocationKind, TaxIdentifierValidationStatus, TaxRemittance, WeightUnit } from './Enums'
+export type { ClaimResolution, ClaimStatus, CountryCode, CurrencyCode, DeliveryStatus, DimensionUnit, ExchangeStatus, FileUploadVisibility, FulfillmentStatus, ImportRowStatus, ImportStatus, InvitationStatus, MediaType, OptionTypeKind, OrderFulfillmentStatus, OrderPaymentStatus, OrderStatus, PackageTypeKind, PayoutScheduleInterval, ProductStatus, ProductSubmissionStatus, PurchaseUnit, ReturnStatus, SellerRequirementState, SellerRequirementSubmissionStatus, SellerStatus, ShippingLabelFormat, ShippingLabelOwnerType, ShippingLabelSource, ShippingLabelStatus, StockLocationKind, TaxIdentifierValidationStatus, TaxRemittance, TimeZone, WeightUnit } from './Enums'
export type { default as Category } from './Category'
export type { default as CustomField } from './CustomField'
export type { default as OptionType } from './OptionType'
diff --git a/spree/api/app/controllers/spree/api/v3/admin/store_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/store_controller.rb
index 365a33fdc4..e988fc2460 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/store_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/store_controller.rb
@@ -13,8 +13,9 @@ module Spree
body.attribute :meta_description, :string,
nullable: true,
description: "The storefront's default meta description, in the store's default language."
- body.attribute :admin_locale, :string, example: 'en'
- body.attribute :timezone, :string, example: 'Europe/Berlin'
+ body.attribute :admin_locale, :locale, nullable: true, example: 'en',
+ description: 'The language the dashboard opens in for every staff member; null lets each use their own.'
+ body.attribute :timezone, :time_zone, example: 'Europe/Berlin'
body.attribute :weight_unit, :weight_unit
body.attribute :unit_system, :string, choices: Spree::Store::UNIT_SYSTEMS
body.attribute :storefront_access, :string,
diff --git a/spree/api/app/serializers/spree/api/v3/admin/store_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/store_serializer.rb
index 947b38f5e0..697934ab9a 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/store_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/store_serializer.rb
@@ -5,7 +5,7 @@ module Spree
class StoreSerializer < V3::StoreSerializer
typelize url: :string, code: :string, api_url: :string,
default_currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'], default_locale: [:string, enum: Spree::Locales::ALL, enum_type_name: 'LocaleCode'],
- default_country_code: [:string, nullable: true],
+ default_country_code: [:string, nullable: true, enum: Spree::IsoData.country_codes, enum_type_name: 'CountryCode'],
supported_currencies: [:string, multi: true, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'],
supported_locales: [:string, multi: true, enum: Spree::Locales::ALL, enum_type_name: 'LocaleCode'],
available_locales: [:string, multi: true, enum: Spree::Locales::ALL, enum_type_name: 'LocaleCode'],
diff --git a/spree/api/app/serializers/spree/api/v3/base_serializer.rb b/spree/api/app/serializers/spree/api/v3/base_serializer.rb
index d51a73a9b9..cb95c17412 100644
--- a/spree/api/app/serializers/spree/api/v3/base_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/base_serializer.rb
@@ -152,6 +152,12 @@ module Spree
}.freeze
private_constant :PREFERENCE_LIST_NAMES
+ # Settings declared with a code format share the code list request
+ # bodies take, so a value read back is the type a write takes.
+ FORMAT_CODE_LISTS = { 'iso-country' => :country, 'currency' => :currency, 'locale' => :locale,
+ 'timezone' => :time_zone }.freeze
+ private_constant :FORMAT_CODE_LISTS
+
def self.preference_type_hint(schema, name)
types = Array(schema['type'])
options = {}
@@ -165,6 +171,9 @@ module Spree
if schema['enum']
options[:enum] = schema['enum'].compact
options[:enum_type_name] = PREFERENCE_LIST_NAMES[name.to_sym] if PREFERENCE_LIST_NAMES.key?(name.to_sym)
+ elsif (code_list = FORMAT_CODE_LISTS[(schema['items'] || schema)['format']])
+ options[:enum_type_name], values = Spree::Api::V3::RequestSchema::CODE_LISTS.fetch(code_list)
+ options[:enum] = values.call
end
options.empty? ? hint : [hint, options]
end
diff --git a/spree/api/app/serializers/spree/api/v3/seller/profile_serializer.rb b/spree/api/app/serializers/spree/api/v3/seller/profile_serializer.rb
index 5e7c3cfcea..72907b6968 100644
--- a/spree/api/app/serializers/spree/api/v3/seller/profile_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/seller/profile_serializer.rb
@@ -17,7 +17,7 @@ module Spree
products_count: :number,
default_currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'],
supported_currencies: [:string, multi: true, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'],
- timezone: [:string, nullable: true]
+ timezone: [:string, nullable: true, enum: Spree::TimeZones::SUGGESTED, enum_type_name: 'TimeZone']
attributes :timezone,
:status, :legal_name, :registration_number,
diff --git a/spree/api/app/services/spree/api/v3/request_schema.rb b/spree/api/app/services/spree/api/v3/request_schema.rb
index 296e7022f3..2d5e02b962 100644
--- a/spree/api/app/services/spree/api/v3/request_schema.rb
+++ b/spree/api/app/services/spree/api/v3/request_schema.rb
@@ -40,22 +40,25 @@ module Spree
datetime: { type: :string, format: :'date-time' },
id: { type: :string },
any: {},
- # Codes from the closed lists below.
+ # Codes from the lists below.
country: { type: :string },
currency: { type: :string },
locale: { type: :string },
+ time_zone: { type: :string },
weight_unit: { type: :string },
dimension_unit: { type: :string }
}.freeze
- # The closed lists a code field takes, published once per API as a
- # named component — the same `CountryCode`, `CurrencyCode` and
- # `WeightUnit` types the serializers declare, so a value read from a
- # response is the type a request takes.
+ # The lists a code field takes, published once per API as a named
+ # component — the same `CountryCode`, `CurrencyCode` and `WeightUnit`
+ # types the serializers declare, so a value read from a response is the
+ # type a request takes. A list `Typelizer::OpenEnums` does not close
+ # only suggests its values.
CODE_LISTS = {
country: ['CountryCode', -> { Spree::IsoData.country_codes }],
currency: ['CurrencyCode', -> { Spree::Money::Rounding::CURRENCY_CODES }],
locale: ['LocaleCode', -> { Spree::Locales::ALL }],
+ time_zone: ['TimeZone', -> { Spree::TimeZones::SUGGESTED }],
weight_unit: ['WeightUnit', -> { Spree::Variant::WEIGHT_UNITS }],
dimension_unit: ['DimensionUnit', -> { Spree::Variant::DIMENSION_UNITS }]
}.freeze
@@ -348,7 +351,12 @@ module Spree
next unless CODE_LISTS.key?(field.kind)
name, values = CODE_LISTS[field.kind]
- lists[name] = { type: :string, enum: values.call }
+ lists[name] = if Typelizer::OpenEnums.closed?(name)
+ { type: :string, enum: values.call }
+ else
+ Typelizer::OpenEnums.open_schema({ type: :string }, values.call)
+ .merge(description: Typelizer::OpenEnums.description(name)).compact
+ end
end
end
@@ -469,7 +477,7 @@ module Spree
# The same open list the serializers publish (`enum_type_name`):
# clients autocomplete the built-in values and still accept any other.
- { anyOf: [schema.merge(enum: field.enum), schema] }
+ Typelizer::OpenEnums.open_schema(schema, field.enum)
end
end
end
diff --git a/spree/api/lib/spree/api/enum_types.rb b/spree/api/lib/spree/api/enum_types.rb
index ddd2530007..6b643e1e61 100644
--- a/spree/api/lib/spree/api/enum_types.rb
+++ b/spree/api/lib/spree/api/enum_types.rb
@@ -110,7 +110,8 @@ module Spree
type = "export type #{name} = (typeof #{constant})[number] | (string & {})"
type = "export type #{name} =\n | (typeof #{constant})[number]\n | (string & {})" if type.length > LINE_WIDTH
- "\n/** The built-in values of `#{name}`. Extensions may add more. */\n#{line}\n#{type}\n"
+ summary = Typelizer::OpenEnums.description(name) || "The built-in values of `#{name}`. Extensions may add more."
+ "\n/** #{summary} */\n#{line}\n#{type}\n"
end
end
end
diff --git a/spree/api/lib/typelizer/open_enums.rb b/spree/api/lib/typelizer/open_enums.rb
index 3201d9b879..f026617ed6 100644
--- a/spree/api/lib/typelizer/open_enums.rb
+++ b/spree/api/lib/typelizer/open_enums.rb
@@ -34,6 +34,25 @@ module Typelizer
TaxRemittance UnitSystem
].freeze
+ # Open lists whose values are suggestions rather than built-ins an
+ # extension adds to, described as such wherever the list is published.
+ DESCRIPTIONS = {
+ 'TimeZone' => 'Common IANA time zones; any other IANA time zone identifier is accepted too.'
+ }.freeze
+
+ # @param name [String, nil] a list's `enum_type_name`
+ # @return [String, nil] what the list's values are, when they are not built-ins
+ def self.description(name)
+ DESCRIPTIONS[name]
+ end
+
+ # @param schema [Hash] the schema of any value in the list
+ # @param values [Array<String>] the values to suggest
+ # @return [Hash] a schema suggesting the values while accepting any other
+ def self.open_schema(schema, values)
+ { anyOf: [schema.merge(enum: values), schema] }
+ end
+
# @param name [String, nil] a list's `enum_type_name`
# @return [Boolean] whether the list is closed: no value outside it is valid
def self.closed?(name)
@@ -63,7 +82,7 @@ module Typelizer
return super unless property.enum_type_name && property.enum.is_a?(Array) && !property.multi
return super if OpenEnums.closed?(property.enum_type_name)
- open = { anyOf: [{ type: :string, enum: property.enum.compact }, { type: :string }] }
+ open = OpenEnums.open_schema({ type: :string }, property.enum.compact)
# OpenAPI 3.0 ignores `nullable` beside `anyOf`, which is where
# Typelizer puts it, so the free-string branch carries it instead.
if property.nullable && !v31?(openapi_version)
@@ -72,7 +91,7 @@ module Typelizer
apply_nullable(open, property, openapi_version: openapi_version)
end
apply_metadata(open, property)
- open[:description] ||= OPEN_ENUM_DESCRIPTION
+ open[:description] ||= OpenEnums.description(property.enum_type_name) || OPEN_ENUM_DESCRIPTION
open
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/store_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/store_controller_spec.rb
index 9bdddef74d..e8b39d4ef2 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/store_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/store_controller_spec.rb
@@ -486,6 +486,55 @@ RSpec.describe Spree::Api::V3::Admin::StoreController, type: :controller do
end
end
+ context 'with a time zone' do
+ let(:params) { { timezone: 'Eastern Time (US & Canada)' } }
+
+ it 'stores its IANA name' do
+ subject
+ expect(response).to have_http_status(:ok)
+ expect(json_response['timezone']).to eq('America/New_York')
+ end
+
+ context 'that names no time zone' do
+ let(:params) { { timezone: 'Mars/Olympus_Mons' } }
+
+ it 'returns a validation error' do
+ subject
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(json_response['error']['details']).to have_key('timezone')
+ end
+ end
+ end
+
+ context 'with an admin language' do
+ let(:params) { { admin_locale: 'pt_br' } }
+
+ it 'stores its listed spelling' do
+ subject
+ expect(json_response['admin_locale']).to eq('pt-BR')
+ end
+
+ context 'that is null' do
+ let(:params) { { admin_locale: nil } }
+
+ it 'accepts it as no override' do
+ subject
+ expect(response).to have_http_status(:ok)
+ expect(json_response['admin_locale']).to be_blank
+ end
+ end
+
+ context 'that Spree does not list' do
+ let(:params) { { admin_locale: 'klingon' } }
+
+ it 'returns a validation error' do
+ subject
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(json_response['error']['details']).to have_key('admin_locale')
+ end
+ end
+ end
+
context 'with an invalid storefront_access value' do
let(:params) { { storefront_access: 'nonsense' } }
diff --git a/spree/api/spec/services/spree/api/v3/request_schema_spec.rb b/spree/api/spec/services/spree/api/v3/request_schema_spec.rb
index 84932ee0ab..50de7af15e 100644
--- a/spree/api/spec/services/spree/api/v3/request_schema_spec.rb
+++ b/spree/api/spec/services/spree/api/v3/request_schema_spec.rb
@@ -124,6 +124,16 @@ RSpec.describe Spree::Api::V3::RequestSchema do
expect(schema.permit_list).to eq([:country_code, { currencies: [] }])
end
+ it 'publishes the time zone list as suggestions that accept any other zone' do
+ schema = described_class.new { |schema| schema.attribute :timezone, :time_zone }
+
+ expect(schema.json_schema[:properties][:timezone]).to eq('$ref': '#/components/schemas/TimeZone')
+ expect(schema.code_lists['TimeZone']).to eq(
+ anyOf: [{ type: :string, enum: Spree::TimeZones::SUGGESTED }, { type: :string }],
+ description: Typelizer::OpenEnums.description('TimeZone')
+ )
+ end
+
it 'sends decimals as canonical strings' do
expect(price.json_schema[:properties][:amount]).to include(type: :string, format: :decimal)
end
diff --git a/spree/core/app/maintenance_tasks/spree/maintenance_tasks/upgrade/store_regional_settings.rb b/spree/core/app/maintenance_tasks/spree/maintenance_tasks/upgrade/store_regional_settings.rb
new file mode 100644
index 0000000000..c094de257e
--- /dev/null
+++ b/spree/core/app/maintenance_tasks/spree/maintenance_tasks/upgrade/store_regional_settings.rb
@@ -0,0 +1,63 @@
+module Spree
+ module MaintenanceTasks
+ module Upgrade
+ # 5.6 → 6.0 conversion of the store's time zone into an IANA identifier
+ # ("Eastern Time (US & Canada)" becomes "America/New_York") and of its
+ # admin language into a listed locale code (`en_US` becomes `en-US`), the
+ # only forms the API accepts and browsers read.
+ #
+ # A time zone that names no zone falls back to the store default, which is
+ # what the store already ran on: Ruby could not read it either. An admin
+ # language Spree does not list is cleared, so the dashboard shows each
+ # staff member their own language.
+ class StoreRegionalSettings < Spree::MaintenanceTask
+ supports_dry_run
+
+ def collection
+ Spree::Store.with_deleted.order(:id)
+ end
+
+ # Locks the store's row, so a settings save made meanwhile is read
+ # rather than overwritten, and counts each change once it is written.
+ #
+ # @param store [Spree::Store]
+ # @return [void]
+ def process(store)
+ store.with_lock do
+ changes = time_zone_change(store).merge(admin_locale_change(store))
+ next if changes.empty?
+
+ if dry_run?
+ changes.each_value { |outcome, _value| tally(:"would_#{outcome}") }
+ next
+ end
+
+ changes.each { |name, (_outcome, value)| store.set_preference(name, value) }
+ store.update_columns(preferences: store.preferences, updated_at: Time.current)
+ changes.each_value { |outcome, _value| tally(outcome) }
+ end
+ end
+
+ private
+
+ def time_zone_change(store)
+ stored = store.preferred_timezone
+ return {} if Spree::TimeZones.valid?(stored)
+
+ converted = Spree::TimeZones.normalize(stored)
+ return { timezone: [:time_zone_converted, converted] } if Spree::TimeZones.valid?(converted)
+
+ { timezone: [:time_zone_reset_to_default, store.preference_default(:timezone)] }
+ end
+
+ def admin_locale_change(store)
+ stored = store.preferred_admin_locale
+ return {} if stored.blank? || Spree::Locales::ALL.include?(stored)
+
+ listed = Spree::Locales.listed(stored)
+ { admin_locale: listed ? [:admin_locale_converted, listed] : [:admin_locale_cleared, nil] }
+ end
+ end
+ end
+ end
+end
diff --git a/spree/core/app/models/spree/store.rb b/spree/core/app/models/spree/store.rb
index 415d453bfa..a942106ed1 100644
--- a/spree/core/app/models/spree/store.rb
+++ b/spree/core/app/models/spree/store.rb
@@ -55,8 +55,9 @@ module Spree
UNIT_SYSTEMS = %w[metric imperial].freeze
# general preferences
- preference :admin_locale, :string, format: :locale
- preference :timezone, :string, format: :timezone, default: Time.zone.name
+ preference :admin_locale, :string, format: :locale, parse_on_set: ->(value) { Spree::Locales.listed(value) || value.presence }
+ preference :timezone, :string, format: :timezone, default: Spree::TimeZones.normalize(Time.zone.name),
+ parse_on_set: ->(value) { Spree::TimeZones.normalize(value) }
preference :weight_unit, :string, default: 'lb', choices: -> { Spree::Variant::WEIGHT_UNITS }
preference :unit_system, :string, default: 'imperial', choices: -> { UNIT_SYSTEMS }
# Anonymous identifier of this installation, kept on the default store
@@ -408,6 +409,8 @@ module Spree
message: :invalid_document_number_affix }
validates :preferred_capture_method, inclusion: { in: Spree::CaptureMethod::CAPTURE_METHODS }
validate :preferred_storefront_url_is_an_origin
+ validate :preferred_admin_locale_is_listed
+ validate :preferred_timezone_is_a_time_zone
validate :order_number_sequence_start_unchanged_after_first_number, on: :update
validates :mail_from_address, email: { allow_blank: false }
validates :customer_support_email, email: { allow_blank: true }
@@ -841,6 +844,31 @@ module Spree
errors.add(:preferred_storefront_url, :invalid)
end
+ def preferred_admin_locale_is_listed
+ locale = preferred_admin_locale
+ return if locale.blank? || Spree::Locales::ALL.include?(locale)
+ return if awaiting_upgrade?(:admin_locale) { Spree::Locales.listed(locale) }
+
+ errors.add(:preferred_admin_locale, :inclusion)
+ end
+
+ def preferred_timezone_is_a_time_zone
+ return if Spree::TimeZones.valid?(preferred_timezone)
+ return if awaiting_upgrade?(:timezone) { Spree::TimeZones.valid?(Spree::TimeZones.normalize(preferred_timezone)) }
+
+ errors.add(:preferred_timezone, :invalid)
+ end
+
+ # A value saved before 6.0 that the store settings upgrade step converts
+ # must not block saving the store's other settings until the step runs.
+ # The block says whether the step can convert it.
+ def awaiting_upgrade?(name)
+ return false unless persisted?
+ return false unless public_send(:"preferred_#{name}") == (attribute_was('preferences') || {})[name]
+
+ yield.present?
+ end
+
# The starting value only shapes a counter that does not exist yet — once
# the first number is issued the counter owns the value, so accepting a
# change here would persist a setting that can never apply again. The
diff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rb
index 8d5a2a6d20..1923645c6c 100644
--- a/spree/core/lib/spree/core.rb
+++ b/spree/core/lib/spree/core.rb
@@ -666,6 +666,7 @@ require 'spree/i18n'
require 'spree/iso_data'
require 'spree/localized_number'
require 'spree/measurement'
+require 'spree/time_zones'
require 'spree/translations'
require 'spree/money'
require 'spree/service_module'
diff --git a/spree/core/lib/spree/time_zones.rb b/spree/core/lib/spree/time_zones.rb
new file mode 100644
index 0000000000..0b92713038
--- /dev/null
+++ b/spree/core/lib/spree/time_zones.rb
@@ -0,0 +1,34 @@
+module Spree
+ # Time zones are stored and exchanged as IANA identifiers (`Europe/Berlin`),
+ # the names browsers and every non-Ruby client understand. Rails' display
+ # names ("Eastern Time (US & Canada)") are converted to them on the way in.
+ module TimeZones
+ # The zones clients are offered: the IANA zones Rails gives a display name
+ # to, with plain `UTC` standing in for `Etc/UTC`. Any other valid IANA
+ # identifier is accepted too. The list comes with the Rails version rather
+ # than the machine's time zone database, so generated types match wherever
+ # the same Rails version runs.
+ SUGGESTED = (ActiveSupport::TimeZone::MAPPING.values - ['Etc/UTC'] + ['UTC']).uniq.sort.freeze
+
+ # @param identifier [String, nil]
+ # @return [Boolean] whether the value is an IANA time zone identifier
+ def self.valid?(identifier)
+ return false if identifier.blank?
+
+ TZInfo::Timezone.get(identifier.to_s)
+ true
+ rescue TZInfo::InvalidTimezoneIdentifier
+ false
+ end
+
+ # @param value [String, nil] an IANA identifier or a Rails time zone name
+ # @return [String, nil] the IANA identifier, or the value unchanged when it
+ # names no zone the installed time zone database knows
+ def self.normalize(value)
+ return value if value.blank? || valid?(value)
+
+ identifier = ActiveSupport::TimeZone::MAPPING[value.to_s]
+ valid?(identifier) ? identifier : value
+ end
+ end
+end
diff --git a/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml b/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml
index 8e92077f95..5a254ef39c 100644
--- a/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml
+++ b/spree/core/lib/spree/upgrades/5_6_to_6_0/manifest.yml
@@ -597,6 +597,19 @@ steps:
is dropped in 6.1. Idempotent — only rows without a capture_method are
written.
+ - id: store_regional_settings
+ name: "Convert store time zones and admin languages to standard codes"
+ task_class: "Spree::MaintenanceTasks::Upgrade::StoreRegionalSettings"
+ notes: |
+ A store's time zone is now always an IANA name such as America/New_York,
+ and its admin language a locale code Spree lists, the forms the API
+ accepts and browsers understand. Rails time zone names such as
+ "Eastern Time (US & Canada)" and locale spellings such as en_US are
+ converted. A time zone that names no zone is reset to the store default,
+ which is what the store already ran on; an admin language Spree does not
+ list is cleared, so staff see their own language. Idempotent — stores
+ already on standard codes are skipped.
+
- id: product_types_backfill
name: "Backfill product type store ownership"
task: "spree:product_types:backfill"
diff --git a/spree/core/spec/maintenance_tasks/spree/maintenance_tasks/upgrade/store_regional_settings_spec.rb b/spree/core/spec/maintenance_tasks/spree/maintenance_tasks/upgrade/store_regional_settings_spec.rb
new file mode 100644
index 0000000000..a3a1e5262b
--- /dev/null
+++ b/spree/core/spec/maintenance_tasks/spree/maintenance_tasks/upgrade/store_regional_settings_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper'
+
+RSpec.describe Spree::MaintenanceTasks::Upgrade::StoreRegionalSettings do
+ let(:store) { create(:store, code: "regional-#{SecureRandom.hex(4)}") }
+
+ def store_settings(**settings)
+ store.update_columns(preferences: store.preferences.merge(settings))
+ end
+
+ def run_task
+ result = Spree::MaintenanceTasks::Start.call(task_name: described_class.name, initiated_via: 'cli')
+ Spree::MaintenanceTasks::RunJob.perform_now(result.value.id)
+ result.value.reload
+ end
+
+ it 'converts a Rails time zone name to its IANA name' do
+ store_settings(timezone: 'Eastern Time (US & Canada)')
+
+ run = run_task
+
+ expect(store.reload.preferred_timezone).to eq('America/New_York')
+ expect(run.tallies['time_zone_converted']).to eq(1)
+ end
+
+ it 'resets a value that names no time zone to the default' do
+ store_settings(timezone: 'Mars/Olympus_Mons')
+
+ run = run_task
+
+ expect(store.reload.preferred_timezone).to eq(store.preference_default(:timezone))
+ expect(run.tallies['time_zone_reset_to_default']).to eq(1)
+ end
+
+ it 'converts an admin language to its listed code and clears one Spree does not list' do
+ other_store = create(:store, code: "regional-#{SecureRandom.hex(4)}")
+ store_settings(admin_locale: 'en_US')
+ other_store.update_columns(preferences: other_store.preferences.merge(admin_locale: 'klingon'))
+
+ run = run_task
+
+ expect(store.reload.preferred_admin_locale).to eq('en-US')
+ expect(other_store.reload.preferred_admin_locale).to be_blank
+ expect(run.tallies).to include('admin_locale_converted' => 1, 'admin_locale_cleared' => 1)
+ end
+
+ it 'leaves a store already on an IANA name and a listed language unchanged' do
+ store_settings(timezone: 'Europe/Berlin', admin_locale: 'de')
+
+ run_task
+
+ expect(store.reload).to have_attributes(preferred_timezone: 'Europe/Berlin', preferred_admin_locale: 'de')
+ end
+end
diff --git a/spree/core/spec/models/spree/store_spec.rb b/spree/core/spec/models/spree/store_spec.rb
index 69eb8d444d..117b35f7b9 100644
--- a/spree/core/spec/models/spree/store_spec.rb
+++ b/spree/core/spec/models/spree/store_spec.rb
@@ -968,6 +968,72 @@ describe Spree::Store, type: :model, without_global_store: true do
end
end
+ describe 'preferred_timezone' do
+ let(:store) { create(:store, code: "regional-#{SecureRandom.hex(4)}") }
+
+ it 'converts a Rails time zone name to its IANA name' do
+ store.update!(preferred_timezone: 'Eastern Time (US & Canada)')
+
+ expect(store.preferred_timezone).to eq('America/New_York')
+ end
+
+ it 'keeps an IANA name and UTC as given' do
+ store.update!(preferred_timezone: 'Europe/Berlin')
+ expect(store.preferred_timezone).to eq('Europe/Berlin')
+
+ store.update!(preferred_timezone: 'UTC')
+ expect(store.preferred_timezone).to eq('UTC')
+ end
+
+ it 'rejects a value that names no time zone' do
+ store.preferred_timezone = 'Mars/Olympus_Mons'
+
+ expect(store).not_to be_valid
+ expect(store.errors[:preferred_timezone]).to be_present
+ end
+
+ it 'does not block saving other settings while a Rails name awaits the upgrade step' do
+ store.update_columns(preferences: store.preferences.merge(timezone: 'Eastern Time (US & Canada)'))
+ store.reload
+
+ expect(store.update(preferred_guest_checkout: false)).to be(true)
+ end
+
+ it 'blocks saving while a stored value no upgrade can convert stays in place' do
+ store.update_columns(preferences: store.preferences.merge(timezone: 'Mars/Olympus_Mons'))
+ store.reload
+
+ expect(store.update(preferred_guest_checkout: false)).to be(false)
+ expect(store.errors[:preferred_timezone]).to be_present
+ end
+ end
+
+ describe 'preferred_admin_locale' do
+ let(:store) { create(:store, code: "regional-#{SecureRandom.hex(4)}") }
+
+ it 'stores the listed spelling of a locale code and clears a blank one' do
+ store.update!(preferred_admin_locale: 'pt_br')
+ expect(store.preferred_admin_locale).to eq('pt-BR')
+
+ store.update!(preferred_admin_locale: '')
+ expect(store.preferred_admin_locale).to be_blank
+ end
+
+ it 'rejects a locale Spree does not list' do
+ store.preferred_admin_locale = 'klingon'
+
+ expect(store).not_to be_valid
+ expect(store.errors[:preferred_admin_locale]).to be_present
+ end
+
+ it 'does not block saving other settings while a stored spelling awaits the upgrade step' do
+ store.update_columns(preferences: store.preferences.merge(admin_locale: 'en_US'))
+ store.reload
+
+ expect(store.update(preferred_guest_checkout: false)).to be(true)
+ end
+ end
+
describe 'units' do
let(:store) { build(:store) }