From 1d875a65c01e138e2b8753b76916792400d1852b Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 25 Jul 2026 22:58:41 +0000 Subject: [PATCH] Honor email-templates.active for order-confirmation Skips the send entirely when the admin has deliberately deactivated the order-confirmation template, matching the backend's new toggle for the 7 order-status emails. Distinct from a missing row, which still sends with the hardcoded default wording. Co-Authored-By: Claude Sonnet 5 --- app/lib/orderEmail.ts | 9 ++++++++- app/lib/payload.ts | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/lib/orderEmail.ts b/app/lib/orderEmail.ts index 8174624..a6bc72d 100644 --- a/app/lib/orderEmail.ts +++ b/app/lib/orderEmail.ts @@ -53,7 +53,14 @@ export type OrderConfirmationEmailData = OrderConfirmationData & { // fails (still alerted, same severity as the frontend's own critical-error // path for this checkout flow). export async function sendOrderConfirmationEmail(order: OrderConfirmationEmailData, customerEmail: string): Promise { - const template = (await getEmailTemplate("order-confirmation")) ?? { + const fetchedTemplate = await getEmailTemplate("order-confirmation"); + // `active === false` is a deliberate admin decision to suppress this + // email entirely — distinct from `fetchedTemplate` being null (no row + // saved yet), which still sends below with the hardcoded default + // wording. Checked before the fallback is applied, since the fallback + // object has no `active` field of its own (implicitly always on). + if (fetchedTemplate && !fetchedTemplate.active) return false; + const template = fetchedTemplate ?? { subject: "Bestellt! Deine Ruhe kann kommen 🎉", heading: "Bestellt!", bodyText: "Deine Bestellung ist bei uns eingetrudelt — wir kümmern uns schon liebevoll darum, sie für dich zu packen.", diff --git a/app/lib/payload.ts b/app/lib/payload.ts index 4f6499d..67bfa11 100644 --- a/app/lib/payload.ts +++ b/app/lib/payload.ts @@ -828,6 +828,11 @@ type PayloadEmailTemplate = { heading: string; bodyText: string; footerText: string | null; + // false means the admin deliberately suppressed this email — checked + // by orderEmail.ts before sending order-confirmation, never treated as + // "row missing, use hardcoded default" (that's what a null return from + // this function itself already means). + active: boolean; }; // draft:true is used by app/email-preview/[type]/page.tsx (Live Preview,