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.

Set unit for package types to be blank by default as variants are (#14685)

Kacper Mękarskidf62bfde4ba1
diff --git a/docs/developer/core-concepts/delivery-setup.mdx b/docs/developer/core-concepts/delivery-setup.mdx
index d2800b98be..e9c1c44b4e 100644
--- a/docs/developer/core-concepts/delivery-setup.mdx
+++ b/docs/developer/core-concepts/delivery-setup.mdx
@@ -201,6 +201,12 @@ they know. A box with no dimensions still contributes its weight; a box with
nothing measured contributes nothing, and dimensional pricing has nothing to
work from.
+`dimensions_unit` and `weight_unit` are optional too. A row that names neither
+is read in whatever the store's own units are, so a store trading in inches and
+pounds reads inches and pounds. A row that names them keeps them, which is how
+one store can mix units — a carton measured in centimetres sits beside a pallet
+measured in feet. Variant dimensions work the same way.
+
<Note>
Deleting the default box is refused, and so is switching its flag off when
nothing else would take it. Both would leave quotes with no size and no tare,
diff --git a/packages/dashboard-core/src/pages/package-types.tsx b/packages/dashboard-core/src/pages/package-types.tsx
index 8be14eb7f1..18315c10e0 100644
--- a/packages/dashboard-core/src/pages/package-types.tsx
+++ b/packages/dashboard-core/src/pages/package-types.tsx
@@ -461,23 +461,25 @@ function UnitField({
<Controller
control={form.control}
name={name}
- render={({ field }) => {
- const options = units.map((unit) => ({ value: unit, label: unit }))
- return (
- <Select items={options} value={field.value ?? ''} onValueChange={field.onChange}>
- <SelectTrigger id={`package-type-${name}`}>
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- {options.map((option) => (
- <SelectItem key={option.value} value={option.value}>
- {option.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- )
- }}
+ render={({ field }) => (
+ <Select
+ value={field.value ?? ''}
+ onValueChange={(value) => field.onChange(value || undefined)}
+ >
+ <SelectTrigger id={`package-type-${name}`}>
+ {/* Nothing picked reads as an em dash rather than a blank
+ trigger, the way the variant editor's units do. */}
+ <SelectValue>{(value) => (value as string) || '—'}</SelectValue>
+ </SelectTrigger>
+ <SelectContent>
+ {units.map((unit) => (
+ <SelectItem key={unit} value={unit}>
+ {unit}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ )}
/>
</Field>
)
diff --git a/packages/dashboard-core/src/schemas/package-type.ts b/packages/dashboard-core/src/schemas/package-type.ts
index a5d9107851..fb12a0c9c0 100644
--- a/packages/dashboard-core/src/schemas/package-type.ts
+++ b/packages/dashboard-core/src/schemas/package-type.ts
@@ -48,10 +48,13 @@ export const PACKAGE_TYPE_DEFAULTS: PackageTypeFormValues = {
length: '',
width: '',
height: '',
- dimensions_unit: 'cm',
+ // Left unset, as the variant editor leaves a variant's. A unit reaches the
+ // API only when the merchant picked one; otherwise the store's own units
+ // are recorded on the row
+ dimensions_unit: undefined,
weight: '',
max_weight: '',
- weight_unit: 'kg',
+ weight_unit: undefined,
default: false,
}
@@ -86,10 +89,10 @@ export function packageTypeToFormValues(packageType: PanelPackageType): PackageT
length: packageType.length ?? '',
width: packageType.width ?? '',
height: packageType.height ?? '',
- dimensions_unit: (packageType.dimensions_unit ?? 'cm') as PackageDimensionUnit,
+ dimensions_unit: (packageType.dimensions_unit ?? undefined) as PackageDimensionUnit | undefined,
weight: packageType.weight ?? '',
max_weight: packageType.max_weight ?? '',
- weight_unit: (packageType.weight_unit ?? 'kg') as PackageWeightUnit,
+ weight_unit: (packageType.weight_unit ?? undefined) as PackageWeightUnit | undefined,
default: packageType.default ?? false,
}
}