From 06a00d67e49542a176e4df19e33c63d8ef2b9e70 Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 25 Jul 2026 16:39:56 +0000 Subject: [PATCH] Fix groupPaymentMethodsForCheckout ignoring sortOrder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hardcoded manual rows first, then the combined stripe option — so "Online-Zahlung" (sortOrder 0) showed after "Überweisung (Vorkasse)" (sortOrder 1) in checkout, contradicting the admin's own ordering. Now preserves the fetch's sortOrder-sorted order, splicing the combined entry in at the position of the first stripe row encountered. Co-Authored-By: Claude Sonnet 5 --- app/lib/payload.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/lib/payload.ts b/app/lib/payload.ts index f491efc..5ba34c6 100644 --- a/app/lib/payload.ts +++ b/app/lib/payload.ts @@ -638,9 +638,8 @@ export type CheckoutPaymentOption = PaymentMethod & { hint?: string }; // `manual` rows (Überweisung) pass through unchanged — one real gateway // there, one option, nothing to collapse. export function groupPaymentMethodsForCheckout(methods: PaymentMethod[]): CheckoutPaymentOption[] { - const manual = methods.filter((m) => m.provider !== "stripe"); const stripeMethods = methods.filter((m) => m.provider === "stripe"); - if (stripeMethods.length === 0) return manual; + if (stripeMethods.length === 0) return methods; const combinedIcons = Array.from(new Set(stripeMethods.flatMap((m) => m.icons))); const online: CheckoutPaymentOption = { @@ -650,7 +649,27 @@ export function groupPaymentMethodsForCheckout(methods: PaymentMethod[]): Checko provider: "stripe", hint: "Kreditkarte, PayPal & weitere Methoden — die genaue Zahlungsart wählst du im nächsten Schritt.", }; - return [...manual, online]; + + // Preserve `methods`' own order (already sortOrder-sorted by the fetch) + // instead of hardcoding manual-first — a real bug: "Online-Zahlung" had + // a lower sortOrder than "Überweisung (Vorkasse)" in the admin, but + // this function always put manual rows first regardless, so the + // checkout showed them in the wrong order. Splice the combined entry in + // at the position of the *first* stripe row encountered, drop any + // further stripe rows (already folded into `online`). + const result: CheckoutPaymentOption[] = []; + let onlineInserted = false; + for (const m of methods) { + if (m.provider === "stripe") { + if (!onlineInserted) { + result.push(online); + onlineInserted = true; + } + continue; + } + result.push(m); + } + return result; } export type WerkzeugeCard = {