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.

Let a preference say what it is and what it accepts

Damian Legawiec05e906fb485d
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yaml
index ae44fce91d..0a1df1de68 100644
--- a/docs/api-reference/admin.yaml
+++ b/docs/api-reference/admin.yaml
@@ -21879,12 +21879,12 @@ paths:
label: Option Value(s)
description:
preference_schema:
- - key: eligible_values
- type: array
- default: []
- key: match_policy
type: string
default: any
+ - key: eligible_values
+ type: array
+ default: []
- type: product
label: Product(s)
description:
@@ -31447,9 +31447,9 @@ paths:
stock_location_ids: []
calculator_type: Spree::Calculator::Shipping::FlatRate
calculator_preferences:
+ amounts: {}
amount: '10.0'
currency: USD
- amounts: {}
meta:
page: 1
limit: 25
@@ -31539,9 +31539,9 @@ paths:
stock_location_ids: []
calculator_type: Spree::Calculator::Shipping::FlatRate
calculator_preferences:
+ amounts: {}
amount: '12.5'
currency: USD
- amounts: {}
requestBody:
content:
application/json:
@@ -31646,21 +31646,18 @@ paths:
- type: Spree::Calculator::Shipping::FlatRate
name: Flat rate
preference_schema:
+ - key: amounts
+ type: hash
+ default: {}
- key: amount
type: decimal
default: 0
- key: currency
type: string
default: USD
- - key: amounts
- type: hash
- default: {}
- type: Spree::Calculator::Shipping::FlexiRate
name: Flexible Rate per package item
preference_schema:
- - key: currency
- type: string
- default: USD
- key: first_item
type: decimal
default: 0.0
@@ -31670,18 +31667,21 @@ paths:
- key: max_items
type: integer
default: 0
+ - key: currency
+ type: string
+ default: USD
- type: Spree::Calculator::Shipping::PerItem
name: Flat rate per package item
preference_schema:
+ - key: amounts
+ type: hash
+ default: {}
- key: amount
type: decimal
default: 0
- key: currency
type: string
default: USD
- - key: amounts
- type: hash
- default: {}
- type: Spree::Calculator::Shipping::PriceSack
name: Price sack
preference_schema:
@@ -31700,15 +31700,15 @@ paths:
- type: Spree::Calculator::Shipping::DigitalDelivery
name: Digital Delivery
preference_schema:
+ - key: amounts
+ type: hash
+ default: {}
- key: amount
type: decimal
default: 0
- key: currency
type: string
default: USD
- - key: amounts
- type: hash
- default: {}
"/api/v3/admin/delivery_zones":
post:
summary: Create delivery zone
@@ -34173,18 +34173,18 @@ paths:
accepted_content_types: []
association_fields: []
preference_schema:
- - key: require_cover_photo
- type: boolean
- default: false
- - key: require_contact_email
- type: boolean
- default: true
- key: require_about
type: boolean
default: true
- key: require_logo
type: boolean
default: true
+ - key: require_cover_photo
+ type: boolean
+ default: false
+ - key: require_contact_email
+ type: boolean
+ default: true
- type: billing_address
name: Billing address
description: The address your payouts are billed from
diff --git a/docs/api-reference/seller.yaml b/docs/api-reference/seller.yaml
index accce17d1d..5b5e1b8b18 100644
--- a/docs/api-reference/seller.yaml
+++ b/docs/api-reference/seller.yaml
@@ -12351,9 +12351,9 @@ paths:
delivery_zone_id:
calculator_type: Spree::Calculator::Shipping::FlatRate
calculator_preferences:
+ amounts: {}
amount: '10.0'
currency: USD
- amounts: {}
- id: dm_gbHJdmfrXB
name: Marketplace post
code: UPS_GROUND
@@ -12373,9 +12373,9 @@ paths:
delivery_zone_id:
calculator_type: Spree::Calculator::Shipping::FlatRate
calculator_preferences:
+ amounts: {}
amount: '10.0'
currency: USD
- amounts: {}
meta:
page: 1
limit: 25
@@ -12442,9 +12442,9 @@ paths:
delivery_zone_id:
calculator_type: Spree::Calculator::Shipping::FlatRate
calculator_preferences:
+ amounts: {}
amount: '9.99'
currency: USD
- amounts: {}
schema:
"$ref": "#/components/schemas/DeliveryMethod"
'422':
@@ -12552,9 +12552,9 @@ paths:
delivery_zone_id:
calculator_type: Spree::Calculator::Shipping::FlatRate
calculator_preferences:
+ amounts: {}
amount: '10.0'
currency: USD
- amounts: {}
schema:
"$ref": "#/components/schemas/DeliveryMethod"
patch:
@@ -12591,9 +12591,9 @@ paths:
delivery_zone_id:
calculator_type: Spree::Calculator::Shipping::FlatRate
calculator_preferences:
+ amounts: {}
amount: '10.0'
currency: USD
- amounts: {}
schema:
"$ref": "#/components/schemas/DeliveryMethod"
requestBody:
@@ -12692,10 +12692,10 @@ paths:
description: Limits the delivery method to packages within a weight
range
preference_schema:
- - key: maximum_weight
+ - key: minimum_weight
type: decimal
default:
- - key: minimum_weight
+ - key: maximum_weight
type: decimal
default:
schema:
@@ -12747,21 +12747,18 @@ paths:
- type: Spree::Calculator::Shipping::FlatRate
name: Flat rate
preference_schema:
+ - key: amounts
+ type: hash
+ default: {}
- key: amount
type: decimal
default: 0
- key: currency
type: string
default: USD
- - key: amounts
- type: hash
- default: {}
- type: Spree::Calculator::Shipping::FlexiRate
name: Flexible Rate per package item
preference_schema:
- - key: currency
- type: string
- default: USD
- key: first_item
type: decimal
default: 0.0
@@ -12771,18 +12768,21 @@ paths:
- key: max_items
type: integer
default: 0
+ - key: currency
+ type: string
+ default: USD
- type: Spree::Calculator::Shipping::PerItem
name: Flat rate per package item
preference_schema:
+ - key: amounts
+ type: hash
+ default: {}
- key: amount
type: decimal
default: 0
- key: currency
type: string
default: USD
- - key: amounts
- type: hash
- default: {}
- type: Spree::Calculator::Shipping::PriceSack
name: Price sack
preference_schema:
@@ -12801,15 +12801,15 @@ paths:
- type: Spree::Calculator::Shipping::DigitalDelivery
name: Digital Delivery
preference_schema:
+ - key: amounts
+ type: hash
+ default: {}
- key: amount
type: decimal
default: 0
- key: currency
type: string
default: USD
- - key: amounts
- type: hash
- default: {}
schema:
type: object
properties:
diff --git a/packages/admin-sdk/src/params.ts b/packages/admin-sdk/src/params.ts
index 2ae9936297..ebc5ad58be 100644
--- a/packages/admin-sdk/src/params.ts
+++ b/packages/admin-sdk/src/params.ts
@@ -1960,6 +1960,12 @@ export interface PreferenceField {
key: string
type: string
default: unknown
+ /**
+ * The fixed set this value must come from, when the preference declares
+ * one. Present only for constrained preferences; an admin form renders a
+ * picker for these rather than a free-text box.
+ */
+ choices?: string[]
}
/**
diff --git a/packages/admin-sdk/src/types/generated/DeliveryMethodRule.ts b/packages/admin-sdk/src/types/generated/DeliveryMethodRule.ts
index 02ca146852..a85e034dca 100644
--- a/packages/admin-sdk/src/types/generated/DeliveryMethodRule.ts
+++ b/packages/admin-sdk/src/types/generated/DeliveryMethodRule.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 1a2fbc5517ea0d5a54e09c26c3922855
+// Typelizer digest 507b98d053b2d70d09f40733bb8289da
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -11,7 +11,7 @@ interface DeliveryMethodRule {
name: string;
description: string;
preferences: Record<string, unknown>;
- preference_schema: Array<{ key: string; type: string; default: unknown }>;
+ preference_schema: Array<{ key: string; type: string; default: unknown; choices?: string[] }>;
product_ids: Array<string>;
}
diff --git a/packages/admin-sdk/src/types/generated/Integration.ts b/packages/admin-sdk/src/types/generated/Integration.ts
index bace1ef785..d9443320e9 100644
--- a/packages/admin-sdk/src/types/generated/Integration.ts
+++ b/packages/admin-sdk/src/types/generated/Integration.ts
@@ -1,4 +1,4 @@
-// Typelizer digest c130808f6213c3b4dc8a02568d441fde
+// Typelizer digest f094c6bc0a9dc18675cc15ec44884213
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -11,7 +11,7 @@ interface Integration {
type: string;
group: string | null;
preferences: Record<string, unknown>;
- preference_schema: Array<{ key: string; type: string; default: unknown }>;
+ preference_schema: Array<{ key: string; type: string; default: unknown; choices?: string[] }>;
}
export default Integration;
diff --git a/packages/admin-sdk/src/types/generated/OrderRoutingRule.ts b/packages/admin-sdk/src/types/generated/OrderRoutingRule.ts
index 88766ba0f2..2798e91f3c 100644
--- a/packages/admin-sdk/src/types/generated/OrderRoutingRule.ts
+++ b/packages/admin-sdk/src/types/generated/OrderRoutingRule.ts
@@ -1,4 +1,4 @@
-// Typelizer digest ed28efbed6eef00b787ae85890f81e74
+// Typelizer digest e5aaefa92f1ae9e327fdf3ce67ed396b
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -11,7 +11,7 @@ interface OrderRoutingRule {
type: string;
channel_id: string;
preferences: Record<string, unknown>;
- preference_schema: Array<{ key: string; type: string; default: unknown }>;
+ preference_schema: Array<{ key: string; type: string; default: unknown; choices?: string[] }>;
label: string;
description: string;
}
diff --git a/packages/admin-sdk/src/types/generated/PaymentMethod.ts b/packages/admin-sdk/src/types/generated/PaymentMethod.ts
index 52c9a9ef05..de8df44176 100644
--- a/packages/admin-sdk/src/types/generated/PaymentMethod.ts
+++ b/packages/admin-sdk/src/types/generated/PaymentMethod.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 35657984d690863d8a80045aa1c18282
+// Typelizer digest 339f411c35f71375c6ca6e10d8d4578f
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -19,7 +19,7 @@ interface PaymentMethod {
created_at: string;
updated_at: string;
preferences: Record<string, unknown>;
- preference_schema: Array<{ key: string; type: string; default: unknown }>;
+ preference_schema: Array<{ key: string; type: string; default: unknown; choices?: string[] }>;
}
export default PaymentMethod;
diff --git a/packages/admin-sdk/src/types/generated/PromotionAction.ts b/packages/admin-sdk/src/types/generated/PromotionAction.ts
index 108f845b6a..f0bb0eb7b7 100644
--- a/packages/admin-sdk/src/types/generated/PromotionAction.ts
+++ b/packages/admin-sdk/src/types/generated/PromotionAction.ts
@@ -1,4 +1,4 @@
-// Typelizer digest d8d786c45e83537b5ab1d43b6b24d771
+// Typelizer digest 3a9aa2cf5885de408ac46c61403b80d5
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -9,7 +9,7 @@ interface PromotionAction {
type: string;
promotion_id: string;
preferences: Record<string, unknown>;
- preference_schema: Array<{ key: string; type: string; default: unknown }>;
+ preference_schema: Array<{ key: string; type: string; default: unknown; choices?: string[] }>;
label: string;
calculator: { type: string; label: string; preferences: Record<string, unknown>; preference_schema: Array<{ key: string; type: string; default: unknown }> } | null;
line_items: Array<{ variant_id: string; quantity: number }> | null;
diff --git a/packages/admin-sdk/src/types/generated/PromotionRule.ts b/packages/admin-sdk/src/types/generated/PromotionRule.ts
index 07da5afd81..b0bc19056e 100644
--- a/packages/admin-sdk/src/types/generated/PromotionRule.ts
+++ b/packages/admin-sdk/src/types/generated/PromotionRule.ts
@@ -1,4 +1,4 @@
-// Typelizer digest b95459445f23419cfaf82c940e4c4428
+// Typelizer digest 1aa7538532dddc0cca10ba1c435e7dbd
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Product, Category, Customer, CustomerGroup, Country, Channel, Market, OptionValue} from '@/types'
@@ -10,7 +10,7 @@ interface PromotionRule {
type: string;
promotion_id: string;
preferences: Record<string, unknown>;
- preference_schema: Array<{ key: string; type: string; default: unknown }>;
+ preference_schema: Array<{ key: string; type: string; default: unknown; choices?: string[] }>;
label: string;
product_ids: Array<string> | null;
category_ids: Array<string> | null;
diff --git a/packages/dashboard-core/src/components/preferences-form.tsx b/packages/dashboard-core/src/components/preferences-form.tsx
index 61059f30d2..c43b965261 100644
--- a/packages/dashboard-core/src/components/preferences-form.tsx
+++ b/packages/dashboard-core/src/components/preferences-form.tsx
@@ -2,10 +2,16 @@ import type { PreferenceField as PreferenceFieldDef } from '@spree/admin-sdk'
import {
Button,
Field,
+ FieldDescription,
FieldGroup,
FieldLabel,
Input,
SecretInput,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
Switch,
Textarea,
} from '@spree/dashboard-ui'
@@ -129,6 +135,11 @@ export function PreferenceField({
const preferenceKey = `admin.preferences.${field.key}`
const displayLabel =
label ?? (i18n.exists(preferenceKey) ? t(preferenceKey) : humanizeKey(field.key))
+ // Optional one-line help, under the same key convention as the label. Most
+ // preferences say what they are in their name; the ones that do not — a
+ // customs signer, an incoterm — are unguessable without it.
+ const descriptionKey = `${preferenceKey}_description`
+ const description = i18n.exists(descriptionKey) ? t(descriptionKey) : undefined
// Currency-typed preferences (`currency`, `default_currency`,
// `display_currency`, …) get the store's CurrencySelect — same
@@ -245,6 +256,41 @@ export function PreferenceField({
)
default:
+ // A preference that declares a fixed set is a picker, not a text box:
+ // the set is what the server validates against, so typing anything
+ // else can only fail on save.
+ if (field.choices?.length) {
+ const options = field.choices.map((choice) => ({
+ value: choice,
+ label: i18n.exists(`${preferenceKey}_options.${choice}`)
+ ? t(`${preferenceKey}_options.${choice}`)
+ : humanizeKey(choice),
+ }))
+
+ return (
+ <Field>
+ <FieldLabel htmlFor={id}>{displayLabel}</FieldLabel>
+ <Select
+ items={options}
+ value={(value as string) ?? ''}
+ onValueChange={(next) => onChange(next ?? '')}
+ >
+ <SelectTrigger id={id}>
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {options.map((option) => (
+ <SelectItem key={option.value} value={option.value}>
+ {option.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ {description && <FieldDescription>{description}</FieldDescription>}
+ </Field>
+ )
+ }
+
return (
<Field>
<FieldLabel htmlFor={id}>{displayLabel}</FieldLabel>
@@ -253,6 +299,7 @@ export function PreferenceField({
value={(value as string) ?? ''}
onChange={(e) => onChange(e.target.value)}
/>
+ {description && <FieldDescription>{description}</FieldDescription>}
</Field>
)
}
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 99e5826cc9..c4c92e2133 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -3945,12 +3945,42 @@
"preferences": {
"additional_item": "Additional Item Cost",
"amount": "كمية",
+ "api_key": "مفتاح API",
+ "api_key_description": "يوجد في لوحة تحكم EasyPost. مفتاح الاختبار والمفتاح الحي يعملان بشكل مختلف — المفتاح نفسه يحدد الوضع.",
"base_amount": "Base Amount",
"base_percent": "Base Percent",
"currency": "Currency",
+ "customs_contents_type": "نوع محتويات البيان الجمركي",
+ "customs_contents_type_description": "ما يحتويه الطرد الدولي وفق تصنيف الجمارك.",
+ "customs_contents_type_options": {
+ "dangerous_goods": "بضائع خطرة",
+ "documents": "مستندات",
+ "gift": "هدية",
+ "humanitarian_donation": "تبرع إنساني",
+ "merchandise": "بضائع",
+ "returned_goods": "بضائع مرتجعة",
+ "sample": "عينة"
+ },
+ "customs_signer": "موقّع البيان الجمركي",
+ "customs_signer_description": "الشخص في شركتك الذي يتحمل المسؤولية القانونية عما يصرّح به الطرد الدولي.",
"discount_amount": "Discount Amount",
"first_item": "First Item Cost",
"flat_percent": "Flat Percent",
+ "incoterm": "الرسوم والضرائب (إنكوترمز)",
+ "incoterm_description": "من يدفع الرسوم عند الوصول. DAP تُحمّل المستلم، وDDP تُحمّلك أنت — لا تختر DDP إلا إذا كنت تحصّل الرسوم عند الدفع.",
+ "incoterm_options": {
+ "CFR": "CFR",
+ "CIF": "CIF",
+ "CIP": "CIP",
+ "CPT": "CPT",
+ "DAT": "DAT",
+ "DAP": "DAP",
+ "DDP": "DDP",
+ "EXW": "EXW",
+ "FAS": "FAS",
+ "FCA": "FCA",
+ "FOB": "FOB"
+ },
"max_items": "Max Items",
"max_quantity": "الحد الأقصى للكمية",
"maximum_item_total": "الحد الأقصى لإجمالي المنتجات",
@@ -3962,7 +3992,9 @@
"normal_amount": "Normal Amount",
"percent": "نسبة مئوية",
"preferred_amount": "كمية",
- "preferred_percent": "نسبة مئوية"
+ "preferred_percent": "نسبة مئوية",
+ "webhook_secret": "مفتاح توقيع الويب هوك",
+ "webhook_secret_description": "السر الذي ضبطته على ويب هوك EasyPost. بدونه تُرفض تحديثات شركة الشحن."
},
"product_types": {
"add_cta": "إضافة نوع منتج",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 3d784dab18..87027ed221 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -3928,12 +3928,42 @@
"preferences": {
"additional_item": "Kosten für jeden weiteren Artikel",
"amount": "Betrag",
+ "api_key": "API-Schlüssel",
+ "api_key_description": "In Ihrem EasyPost-Dashboard zu finden. Test- und Live-Schlüssel verhalten sich unterschiedlich — der Schlüssel bestimmt den Modus.",
"base_amount": "Grundbetrag",
"base_percent": "Grundprozentsatz",
"currency": "Währung",
+ "customs_contents_type": "Zollinhaltsart",
+ "customs_contents_type_description": "Was eine internationale Sendung enthält, wie der Zoll es einstuft.",
+ "customs_contents_type_options": {
+ "dangerous_goods": "Gefahrgut",
+ "documents": "Dokumente",
+ "gift": "Geschenk",
+ "humanitarian_donation": "Humanitäre Spende",
+ "merchandise": "Handelsware",
+ "returned_goods": "Rücksendung",
+ "sample": "Muster"
+ },
+ "customs_signer": "Zollunterzeichner",
+ "customs_signer_description": "Die Person in Ihrem Unternehmen, die rechtlich für die Zollangaben einer internationalen Sendung verantwortlich ist.",
"discount_amount": "Rabattbetrag",
"first_item": "Kosten für den ersten Artikel",
"flat_percent": "Fester Prozentsatz",
+ "incoterm": "Zölle und Steuern (Incoterm)",
+ "incoterm_description": "Wer die Zölle bei Ankunft zahlt. DAP belastet den Empfänger, DDP Sie selbst — wählen Sie DDP nur, wenn Sie Zölle im Checkout erheben.",
+ "incoterm_options": {
+ "CFR": "CFR",
+ "CIF": "CIF",
+ "CIP": "CIP",
+ "CPT": "CPT",
+ "DAT": "DAT",
+ "DAP": "DAP",
+ "DDP": "DDP",
+ "EXW": "EXW",
+ "FAS": "FAS",
+ "FCA": "FCA",
+ "FOB": "FOB"
+ },
"max_items": "Maximale Artikelanzahl",
"max_quantity": "Höchstmenge",
"maximum_item_total": "Maximale Artikelsumme",
@@ -3945,7 +3975,9 @@
"normal_amount": "Normalbetrag",
"percent": "Prozent",
"preferred_amount": "Betrag",
- "preferred_percent": "Prozent"
+ "preferred_percent": "Prozent",
+ "webhook_secret": "Webhook-Signaturschlüssel",
+ "webhook_secret_description": "Das Geheimnis, das Sie im EasyPost-Webhook festgelegt haben. Ohne es werden Carrier-Updates abgelehnt."
},
"product_types": {
"add_cta": "Produkttyp hinzufügen",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index d755df85a9..f9b8056c34 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -3928,12 +3928,42 @@
"preferences": {
"additional_item": "Additional Item Cost",
"amount": "Amount",
+ "api_key": "API key",
+ "api_key_description": "Found in your EasyPost dashboard. A test key and a live key behave differently — the key itself decides the mode.",
"base_amount": "Base Amount",
"base_percent": "Base Percent",
"currency": "Currency",
+ "customs_contents_type": "Customs contents type",
+ "customs_contents_type_description": "What an international parcel holds, as customs classifies it.",
+ "customs_contents_type_options": {
+ "dangerous_goods": "Dangerous goods",
+ "documents": "Documents",
+ "gift": "Gift",
+ "humanitarian_donation": "Humanitarian donation",
+ "merchandise": "Merchandise",
+ "returned_goods": "Returned goods",
+ "sample": "Sample"
+ },
+ "customs_signer": "Customs signer",
+ "customs_signer_description": "The person at your company who takes legal responsibility for what an international parcel declares.",
"discount_amount": "Discount Amount",
"first_item": "First Item Cost",
"flat_percent": "Flat Percent",
+ "incoterm": "Duties and taxes (Incoterm)",
+ "incoterm_description": "Who pays duties on arrival. DAP bills the recipient; DDP bills you, so only pick it if you collect duties at checkout.",
+ "incoterm_options": {
+ "CFR": "CFR",
+ "CIF": "CIF",
+ "CIP": "CIP",
+ "CPT": "CPT",
+ "DAT": "DAT",
+ "DAP": "DAP",
+ "DDP": "DDP",
+ "EXW": "EXW",
+ "FAS": "FAS",
+ "FCA": "FCA",
+ "FOB": "FOB"
+ },
"max_items": "Max Items",
"max_quantity": "Maximum quantity",
"maximum_item_total": "Maximum item total",
@@ -3945,7 +3975,9 @@
"normal_amount": "Normal Amount",
"percent": "Percent",
"preferred_amount": "Amount",
- "preferred_percent": "Percent"
+ "preferred_percent": "Percent",
+ "webhook_secret": "Webhook signing secret",
+ "webhook_secret_description": "The secret you set on the EasyPost webhook. Carrier updates are refused without it."
},
"product_types": {
"add_cta": "Add product type",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index baeb94adba..1bc21092fe 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -3928,12 +3928,42 @@
"preferences": {
"additional_item": "Coût de chaque article supplémentaire",
"amount": "Montant",
+ "api_key": "Clé API",
+ "api_key_description": "Disponible dans votre tableau de bord EasyPost. Une clé de test et une clé live se comportent différemment — la clé détermine le mode.",
"base_amount": "Montant de base",
"base_percent": "Pourcentage de base",
"currency": "Devise",
+ "customs_contents_type": "Type de contenu douanier",
+ "customs_contents_type_description": "Ce que contient un colis international, selon la classification douanière.",
+ "customs_contents_type_options": {
+ "dangerous_goods": "Marchandises dangereuses",
+ "documents": "Documents",
+ "gift": "Cadeau",
+ "humanitarian_donation": "Don humanitaire",
+ "merchandise": "Marchandise",
+ "returned_goods": "Retour de marchandise",
+ "sample": "Échantillon"
+ },
+ "customs_signer": "Signataire douanier",
+ "customs_signer_description": "La personne de votre entreprise qui assume la responsabilité légale du contenu déclaré d'un colis international.",
"discount_amount": "Montant de la remise",
"first_item": "Coût du premier article",
"flat_percent": "Pourcentage fixe",
+ "incoterm": "Droits et taxes (Incoterm)",
+ "incoterm_description": "Qui paie les droits à l'arrivée. DAP facture le destinataire, DDP vous facture — ne choisissez DDP que si vous percevez les droits au paiement.",
+ "incoterm_options": {
+ "CFR": "CFR",
+ "CIF": "CIF",
+ "CIP": "CIP",
+ "CPT": "CPT",
+ "DAT": "DAT",
+ "DAP": "DAP",
+ "DDP": "DDP",
+ "EXW": "EXW",
+ "FAS": "FAS",
+ "FCA": "FCA",
+ "FOB": "FOB"
+ },
"max_items": "Nombre maximal d'articles",
"max_quantity": "Quantité maximale",
"maximum_item_total": "Total articles maximal",
@@ -3945,7 +3975,9 @@
"normal_amount": "Montant normal",
"percent": "Pourcentage",
"preferred_amount": "Montant",
- "preferred_percent": "Pourcentage"
+ "preferred_percent": "Pourcentage",
+ "webhook_secret": "Clé de signature du webhook",
+ "webhook_secret_description": "Le secret défini sur le webhook EasyPost. Sans lui, les mises à jour du transporteur sont refusées."
},
"product_types": {
"add_cta": "Ajouter un type de produit",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 9c2dba6a2a..5ef80291d1 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -3972,12 +3972,42 @@
"preferences": {
"additional_item": "Koszt każdej kolejnej pozycji",
"amount": "Kwota",
+ "api_key": "Klucz API",
+ "api_key_description": "Znajdziesz go w panelu EasyPost. Klucz testowy i produkcyjny działają inaczej — to klucz decyduje o trybie.",
"base_amount": "Kwota podstawowa",
"base_percent": "Procent podstawowy",
"currency": "Waluta",
+ "customs_contents_type": "Rodzaj zawartości celnej",
+ "customs_contents_type_description": "Co zawiera przesyłka międzynarodowa według klasyfikacji celnej.",
+ "customs_contents_type_options": {
+ "dangerous_goods": "Towary niebezpieczne",
+ "documents": "Dokumenty",
+ "gift": "Prezent",
+ "humanitarian_donation": "Dar humanitarny",
+ "merchandise": "Towar handlowy",
+ "returned_goods": "Towar zwrócony",
+ "sample": "Próbka"
+ },
+ "customs_signer": "Osoba podpisująca zgłoszenie celne",
+ "customs_signer_description": "Osoba w Twojej firmie odpowiedzialna prawnie za treść zgłoszenia celnego przesyłki międzynarodowej.",
"discount_amount": "Kwota rabatu",
"first_item": "Koszt pierwszej pozycji",
"flat_percent": "Stały procent",
+ "incoterm": "Cła i podatki (Incoterm)",
+ "incoterm_description": "Kto płaci cło przy odbiorze. DAP obciąża odbiorcę, DDP Ciebie — wybierz DDP tylko, jeśli pobierasz cło przy zamówieniu.",
+ "incoterm_options": {
+ "CFR": "CFR",
+ "CIF": "CIF",
+ "CIP": "CIP",
+ "CPT": "CPT",
+ "DAT": "DAT",
+ "DAP": "DAP",
+ "DDP": "DDP",
+ "EXW": "EXW",
+ "FAS": "FAS",
+ "FCA": "FCA",
+ "FOB": "FOB"
+ },
"max_items": "Maksymalna liczba pozycji",
"max_quantity": "Maksymalna ilość",
"maximum_item_total": "Maksymalna wartość produktów",
@@ -3989,7 +4019,9 @@
"normal_amount": "Kwota normalna",
"percent": "Procent",
"preferred_amount": "Kwota",
- "preferred_percent": "Procent"
+ "preferred_percent": "Procent",
+ "webhook_secret": "Sekret podpisu webhooka",
+ "webhook_secret_description": "Sekret ustawiony na webhooku EasyPost. Bez niego aktualizacje od przewoźnika są odrzucane."
},
"product_types": {
"add_cta": "Dodaj typ produktu",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 9ca0048458..aa6dd8a8cb 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -3920,12 +3920,42 @@
"preferences": {
"additional_item": "附加件费用",
"amount": "金额",
+ "api_key": "API 密钥",
+ "api_key_description": "在您的 EasyPost 控制台中获取。测试密钥与正式密钥行为不同——密钥本身决定模式。",
"base_amount": "基础金额",
"base_percent": "基础百分比",
"currency": "货币",
+ "customs_contents_type": "报关内容类型",
+ "customs_contents_type_description": "按海关分类,国际包裹所含物品的类型。",
+ "customs_contents_type_options": {
+ "dangerous_goods": "危险品",
+ "documents": "文件",
+ "gift": "礼品",
+ "humanitarian_donation": "人道主义捐赠",
+ "merchandise": "商品",
+ "returned_goods": "退回商品",
+ "sample": "样品"
+ },
+ "customs_signer": "报关签署人",
+ "customs_signer_description": "贵公司中对国际包裹申报内容承担法律责任的人员。",
"discount_amount": "折扣金额",
"first_item": "首件费用",
"flat_percent": "固定百分比",
+ "incoterm": "关税与税费(贸易术语)",
+ "incoterm_description": "谁支付到货关税。DAP 向收件人收取,DDP 向您收取——仅在结账时代收关税才选择 DDP。",
+ "incoterm_options": {
+ "CFR": "CFR",
+ "CIF": "CIF",
+ "CIP": "CIP",
+ "CPT": "CPT",
+ "DAT": "DAT",
+ "DAP": "DAP",
+ "DDP": "DDP",
+ "EXW": "EXW",
+ "FAS": "FAS",
+ "FCA": "FCA",
+ "FOB": "FOB"
+ },
"max_items": "最大件数",
"max_quantity": "最大数量",
"maximum_item_total": "最高商品总额",
@@ -3937,7 +3967,9 @@
"normal_amount": "标准金额",
"percent": "百分比",
"preferred_amount": "金额",
- "preferred_percent": "百分比"
+ "preferred_percent": "百分比",
+ "webhook_secret": "Webhook 签名密钥",
+ "webhook_secret_description": "您在 EasyPost webhook 上设置的密钥。缺少它,承运商更新将被拒绝。"
},
"product_types": {
"add_cta": "添加商品类型",
diff --git a/packages/seller-sdk/src/types/generated/DeliveryMethodRule.ts b/packages/seller-sdk/src/types/generated/DeliveryMethodRule.ts
index a9a09f127e..2a1376cb45 100644
--- a/packages/seller-sdk/src/types/generated/DeliveryMethodRule.ts
+++ b/packages/seller-sdk/src/types/generated/DeliveryMethodRule.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 5168bd3caf569ad059d7c2d2d309e85e
+// Typelizer digest c8528681400aeb409ba175a18af3efd4
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -9,7 +9,7 @@ type DeliveryMethodRule = {
name: string;
description: string;
preferences: Record<string, unknown>;
- preference_schema: Array<{ key: string; type: string; default: unknown }>;
+ preference_schema: Array<{ key: string; type: string; default: unknown; choices?: string[] }>;
}
export default DeliveryMethodRule;
diff --git a/spree/api/app/serializers/spree/api/v3/admin/delivery_method_rule_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/delivery_method_rule_serializer.rb
index 3d5138a461..d286f173ce 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/delivery_method_rule_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/delivery_method_rule_serializer.rb
@@ -5,7 +5,7 @@ module Spree
class DeliveryMethodRuleSerializer < BaseSerializer
typelize type: :string, active: :boolean,
preferences: 'Record<string, unknown>',
- preference_schema: "Array<{ key: string; type: string; default: unknown }>",
+ preference_schema: "Array<{ key: string; type: string; default: unknown; choices?: string[] }>",
name: :string, description: :string,
product_ids: [:string, multi: true]
diff --git a/spree/api/app/serializers/spree/api/v3/admin/integration_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/integration_serializer.rb
index d66c574cf6..b971251641 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/integration_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/integration_serializer.rb
@@ -10,7 +10,7 @@ module Spree
group: [:string, nullable: true],
active: :boolean,
preferences: 'Record<string, unknown>',
- preference_schema: "Array<{ key: string; type: string; default: unknown }>"
+ preference_schema: "Array<{ key: string; type: string; default: unknown; choices?: string[] }>"
attributes :name, :active,
created_at: :iso8601, updated_at: :iso8601
diff --git a/spree/api/app/serializers/spree/api/v3/admin/order_routing_rule_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/order_routing_rule_serializer.rb
index 221b708744..d1e68539b2 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/order_routing_rule_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/order_routing_rule_serializer.rb
@@ -13,7 +13,7 @@ module Spree
position: :number,
active: :boolean,
preferences: 'Record<string, unknown>',
- preference_schema: "Array<{ key: string; type: string; default: unknown }>",
+ preference_schema: "Array<{ key: string; type: string; default: unknown; choices?: string[] }>",
label: :string,
description: :string
diff --git a/spree/api/app/serializers/spree/api/v3/admin/payment_method_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/payment_method_serializer.rb
index 8a9ea70fd4..26acf9d39a 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/payment_method_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/payment_method_serializer.rb
@@ -11,7 +11,7 @@ module Spree
position: :number,
metadata: 'Record<string, unknown>',
preferences: 'Record<string, unknown>',
- preference_schema: "Array<{ key: string; type: string; default: unknown }>"
+ preference_schema: "Array<{ key: string; type: string; default: unknown; choices?: string[] }>"
# Null capture_method means the method inherits from its store;
# resolved_capture_method is what actually applies, so the dashboard
diff --git a/spree/api/app/serializers/spree/api/v3/admin/promotion_action_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/promotion_action_serializer.rb
index 5792c48539..2fa625c6d1 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/promotion_action_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/promotion_action_serializer.rb
@@ -12,7 +12,7 @@ module Spree
typelize type: :string,
promotion_id: :string,
preferences: 'Record<string, unknown>',
- preference_schema: "Array<{ key: string; type: string; default: unknown }>",
+ preference_schema: "Array<{ key: string; type: string; default: unknown; choices?: string[] }>",
label: :string,
calculator: "{ type: string; label: string; preferences: Record<string, unknown>; preference_schema: Array<{ key: string; type: string; default: unknown }> } | null",
line_items: 'Array<{ variant_id: string; quantity: number }> | null'
diff --git a/spree/api/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb
index 550e534811..140537814b 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb
@@ -11,7 +11,7 @@ module Spree
typelize type: :string,
promotion_id: :string,
preferences: 'Record<string, unknown>',
- preference_schema: "Array<{ key: string; type: string; default: unknown }>",
+ preference_schema: "Array<{ key: string; type: string; default: unknown; choices?: string[] }>",
label: :string,
product_ids: 'Array<string> | null',
category_ids: 'Array<string> | null',
diff --git a/spree/api/app/serializers/spree/api/v3/seller/delivery_method_rule_serializer.rb b/spree/api/app/serializers/spree/api/v3/seller/delivery_method_rule_serializer.rb
index cc2eb185d8..3e342c23ab 100644
--- a/spree/api/app/serializers/spree/api/v3/seller/delivery_method_rule_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/seller/delivery_method_rule_serializer.rb
@@ -12,7 +12,7 @@ module Spree
class DeliveryMethodRuleSerializer < BaseSerializer
typelize type: :string, active: :boolean,
preferences: 'Record<string, unknown>',
- preference_schema: "Array<{ key: string; type: string; default: unknown }>",
+ preference_schema: "Array<{ key: string; type: string; default: unknown; choices?: string[] }>",
name: :string, description: :string
attributes :active
diff --git a/spree/core/app/models/concerns/spree/preference_schema.rb b/spree/core/app/models/concerns/spree/preference_schema.rb
index 630d982f96..c7c349adae 100644
--- a/spree/core/app/models/concerns/spree/preference_schema.rb
+++ b/spree/core/app/models/concerns/spree/preference_schema.rb
@@ -75,6 +75,7 @@ module Spree
@serialized_preference_schema ||= fields.map do |field|
wire = { key: field[:key], type: field[:type], default: field[:default] }
+ wire[:choices] = field[:choices] if field[:choices].present?
wire[:default] = nil if field[:type] == :password
wire.freeze
end.freeze
@@ -92,6 +93,17 @@ module Spree
.freeze
end
+ # Declared order first, so a form reads the way its author grouped the
+ # fields; anything the macro did not record (an association writer that
+ # looks like a preference) keeps its existing place at the end.
+ def ordered_preferences(instance)
+ defined = instance.defined_preferences
+ return defined unless respond_to?(:declared_preference_order)
+
+ declared = declared_preference_order & defined
+ declared + (defined - declared)
+ end
+
def compute_preference_schema
# Only instantiation is guarded. `new` touches the database to read
# the column list, so it fails whenever the schema is asked for before
@@ -109,7 +121,7 @@ module Spree
return nil
end
- instance.defined_preferences.filter_map do |pref|
+ ordered_preferences(instance).filter_map do |pref|
next if instance.preference_deprecated(pref)
# Written by Spree, not supplied by the operator — a value a
# provider hands back after we register something with it. Offering
@@ -121,8 +133,9 @@ module Spree
key: pref,
key_string: pref.to_s.freeze,
type: instance.preference_type(pref),
- default: safe_preference_default(instance, pref)
- }.freeze
+ default: safe_preference_default(instance, pref),
+ choices: instance.preference_choices(pref)
+ }.compact.freeze
end
end
diff --git a/spree/core/lib/spree/core/preferences/preferable.rb b/spree/core/lib/spree/core/preferences/preferable.rb
index ac88bf8118..ed2c26c955 100644
--- a/spree/core/lib/spree/core/preferences/preferable.rb
+++ b/spree/core/lib/spree/core/preferences/preferable.rb
@@ -81,6 +81,22 @@ module Spree::Preferences::Preferable
send(getter)
end
+ # The fixed set this preference's value must come from, when it has one.
+ # Carried into the schema so an admin form renders a picker rather than a
+ # text box the operator can only get wrong.
+ #
+ # @return [Array, nil]
+ def preference_choices(name)
+ has_preference! name
+ getter = self.class.preference_choices_getter_method(name)
+ # A preference declared before this option existed has no such reader.
+ # Treated as unconstrained rather than raising, so one old declaration
+ # cannot take a whole class's preference schema down with it.
+ return unless respond_to?(getter)
+
+ send(getter)
+ end
+
def has_preference!(name)
raise NoMethodError, "#{name} preference not defined" unless has_preference? name
end
diff --git a/spree/core/lib/spree/core/preferences/preferable_class_methods.rb b/spree/core/lib/spree/core/preferences/preferable_class_methods.rb
index a27e0e8e5a..4bf11c6f8e 100644
--- a/spree/core/lib/spree/core/preferences/preferable_class_methods.rb
+++ b/spree/core/lib/spree/core/preferences/preferable_class_methods.rb
@@ -1,12 +1,28 @@
module Spree::Preferences
module PreferableClassMethods
+ # Declaration order, so an admin form can present preferences the way
+ # their author grouped them — credentials before the optional settings
+ # that depend on them. `defined_preferences` reads Ruby's own `methods`,
+ # whose order is an implementation detail, so it cannot answer this.
+ def declared_preference_order
+ @declared_preference_order ||= begin
+ inherited = superclass.respond_to?(:declared_preference_order) ? superclass.declared_preference_order : []
+ inherited.dup
+ end
+ end
+
def preference(name, type, *args)
+ declared_preference_order << name.to_sym unless declared_preference_order.include?(name.to_sym)
options = args.extract_options!
- options.assert_valid_keys(:default, :deprecated, :internal, :nullable, :parse_on_set)
+ options.assert_valid_keys(:default, :deprecated, :in, :internal, :nullable, :parse_on_set)
default = options[:default]
default = -> { options[:default] } unless default.is_a?(Proc)
deprecated = options[:deprecated]
internal = options[:internal]
+ # The fixed set a value must come from. Turns a text box into a picker
+ # in every admin form, and is what the inclusion validation would have
+ # told the operator only after a failed save.
+ choices = options[:in]
nullable = options[:nullable]
parse_on_set = options[:parse_on_set]
@@ -57,6 +73,10 @@ module Spree::Preferences
internal
end
+ define_method preference_choices_getter_method(name) do
+ choices.respond_to?(:call) ? choices.call : choices
+ end
+
define_method prefers_query_method(name) do
preferences.fetch(name).to_b
end
@@ -110,6 +130,10 @@ module Spree::Preferences
"preferred_#{name}_internal".to_sym
end
+ def preference_choices_getter_method(name)
+ "preferred_#{name}_choices".to_sym
+ end
+
def preference_type_getter_method(name)
"preferred_#{name}_type".to_sym
end
diff --git a/spree/core/spec/models/spree/payment_method_spec.rb b/spree/core/spec/models/spree/payment_method_spec.rb
index 1b9bee2155..9c732d4fc5 100644
--- a/spree/core/spec/models/spree/payment_method_spec.rb
+++ b/spree/core/spec/models/spree/payment_method_spec.rb
@@ -339,6 +339,58 @@ describe Spree::PaymentMethod, type: :model do
end
# A preference the system writes rather than the operator supplies — a
# secret a provider issues, an id it gives back.
+ describe 'constrained preferences' do
+ let(:gateway_class) do
+ Class.new(Spree::Gateway) do
+ def self.name = 'TestConstrainedGateway'
+
+ preference :mode, :string, default: 'live', in: %w[test live]
+ preference :label, :string
+ end
+ end
+
+ # The set is what the server validates against, so a form that does not
+ # know it can only offer a text box the operator gets wrong.
+ it 'carries the set into the schema' do
+ field = gateway_class.serialized_preference_schema.find { |entry| entry[:key] == :mode }
+
+ expect(field[:choices]).to eq(%w[test live])
+ end
+
+ it 'leaves an unconstrained preference without one' do
+ field = gateway_class.serialized_preference_schema.find { |entry| entry[:key] == :label }
+
+ expect(field).not_to have_key(:choices)
+ end
+
+ it 'reports the set for a single preference' do
+ gateway = gateway_class.new
+
+ expect(gateway.preference_choices(:mode)).to eq(%w[test live])
+ expect(gateway.preference_choices(:label)).to be_nil
+ end
+ end
+
+ describe 'preference order' do
+ let(:gateway_class) do
+ Class.new(Spree::Gateway) do
+ def self.name = 'TestOrderedGateway'
+
+ preference :api_key, :password
+ preference :webhook_secret, :password
+ preference :contents_type, :string
+ end
+ end
+
+ # Ruby's `methods` has no meaningful order, so without this the form
+ # presents credentials and optional settings in an arbitrary sequence.
+ it 'follows the order the preferences were declared in' do
+ keys = gateway_class.serialized_preference_schema.map { |field| field[:key] }
+
+ expect(keys.first(3)).to eq(%i[api_key webhook_secret contents_type])
+ end
+ end
+
describe 'internal preferences' do
let(:gateway_class) do
Class.new(Spree::Gateway) do
diff --git a/spree/providers/easypost/app/models/spree_easypost/integration.rb b/spree/providers/easypost/app/models/spree_easypost/integration.rb
index 05d0766e6f..a548c4a104 100644
--- a/spree/providers/easypost/app/models/spree_easypost/integration.rb
+++ b/spree/providers/easypost/app/models/spree_easypost/integration.rb
@@ -2,30 +2,32 @@ module SpreeEasyPost
# Per-store EasyPost credentials. The API key decides the mode — EasyPost
# issues separate test and production keys, so there is no mode toggle.
class Integration < Spree::Integration
+ # EasyPost rejects any other value outright, and a rejected shipment
+ # create is a checkout with no delivery options at all.
+ INCOTERMS = %w[CFR CIF CIP CPT DAT DAP DDP EXW FAS FCA FOB].freeze
+ # EasyPost's contents enum minus `other`, which additionally demands a
+ # free-text explanation nothing here supplies — offering it would only
+ # produce a rejected declaration.
+ CUSTOMS_CONTENTS_TYPES = %w[documents gift merchandise returned_goods sample dangerous_goods humanitarian_donation].freeze
+
+ # Declared credentials first: they are the two an operator must supply,
+ # and the form renders in this order.
preference :api_key, :password
# The shared secret configured on the EasyPost webhook; signs every
# delivery. Without it webhooks are refused — an unauthenticated report
# could otherwise mark parcels delivered, which starts return windows.
preference :webhook_secret, :password
- # Customs declaration defaults for international labels. The signer takes
- # legal responsibility for the declared contents, so it names a person at
- # the merchant rather than the store.
+ # Customs declaration defaults, used only on international labels. The
+ # signer takes legal responsibility for the declared contents, so it names
+ # a person at the merchant rather than the store.
preference :customs_signer, :string
- preference :customs_contents_type, :string, default: 'merchandise'
+ preference :customs_contents_type, :string, default: 'merchandise', in: CUSTOMS_CONTENTS_TYPES
# Who pays duties and taxes on arrival. Defaults to DAP — the recipient is
# billed by the carrier. DDP bills the merchant instead, so only choose it
# once duties are actually collected from the customer at checkout;
# otherwise the merchant absorbs them silently.
- preference :incoterm, :string, default: 'DAP'
-
- # EasyPost rejects any other value outright, and a rejected shipment
- # create is a checkout with no delivery options at all.
- INCOTERMS = %w[CFR CIF CIP CPT DAT DAP DDP EXW FAS FCA FOB].freeze
- # EasyPost's contents enum minus `other`, which additionally demands a
- # free-text explanation nothing here supplies — offering it would only
- # produce a rejected declaration.
- CUSTOMS_CONTENTS_TYPES = %w[documents gift merchandise returned_goods sample dangerous_goods humanitarian_donation].freeze
+ preference :incoterm, :string, default: 'DAP', in: INCOTERMS
validates :preferred_incoterm, inclusion: { in: INCOTERMS }, allow_blank: true
validates :preferred_customs_contents_type, inclusion: { in: CUSTOMS_CONTENTS_TYPES }, allow_blank: true