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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<boolean> {
|
||||
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.",
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user