Feed checkout's country selects from Payload instead of a hardcoded list
Both the billing and shipping-override country selects, plus PLZ maxLength/pattern validation, now read from the new shipping-countries collection (getShippingCountries()) rather than a hardcoded Deutschland/Österreich(/Schweiz) array. Lets an admin add or reorder destination countries without a frontend deploy. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -471,6 +471,46 @@ export async function getShippingMethods(): Promise<ShippingMethod[]> {
|
||||
}));
|
||||
}
|
||||
|
||||
// Feeds /checkout's "Land" <select> (both the billing address and the
|
||||
// optional shipping-address override) and its PLZ digit-count validation
|
||||
// — previously a hardcoded array + PLZ_DIGITS map in CheckoutContent.tsx
|
||||
// itself. Which countries are actually deliverable can now change without
|
||||
// a code deploy (e.g. temporarily dropping Schweiz — no customs/export-
|
||||
// invoice handling exists for it yet). Deliberately unrelated to VAT-
|
||||
// exemption eligibility (lib/vatExemption.ts's isExemptionEligibleCountry(),
|
||||
// still hardcoded to "Österreich") — that's a legal/tax-law question, not
|
||||
// a shipping-logistics one, and stays in code on purpose.
|
||||
export type ShippingCountry = {
|
||||
name: string;
|
||||
plzDigits: number;
|
||||
};
|
||||
|
||||
type PayloadShippingCountry = ShippingCountry & { active: boolean };
|
||||
|
||||
export async function getShippingCountries(): Promise<ShippingCountry[]> {
|
||||
const params = new URLSearchParams({
|
||||
"where[tenant.slug][equals]": TENANT_SLUG,
|
||||
"where[active][equals]": "true",
|
||||
sort: "sortOrder",
|
||||
limit: "20",
|
||||
});
|
||||
|
||||
const res = await fetch(`${PAYLOAD_URL}/api/shipping-countries?${params}`, {
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
if (!res.ok) {
|
||||
console.error(`getShippingCountries: Payload returned ${res.status} ${res.statusText}`);
|
||||
return [];
|
||||
}
|
||||
|
||||
const data: { docs?: PayloadShippingCountry[] } = await res.json();
|
||||
const docs = Array.isArray(data.docs) ? data.docs : [];
|
||||
return docs.map((doc) => ({
|
||||
name: doc.name,
|
||||
plzDigits: doc.plzDigits,
|
||||
}));
|
||||
}
|
||||
|
||||
export type ShippingSettings = {
|
||||
handlingDays: { min: number; max: number };
|
||||
transitDays: { min: number; max: number };
|
||||
|
||||
Reference in New Issue
Block a user