feat(email): per-variant paid/unpaid body templates in settings
The previous single body field could not distinguish 'use the default' from 'save the pre-filled default', so the first settings save locked the hint in as a custom override for ALL orders — the paid/unpaid default logic never ran. Give each payment state its own editable body field (emailBodyHtmlDePaid / emailBodyHtmlEnPaid) with its own empty-fallback. A body submitted unchanged from its built-in default is stored as empty, so 'use default' survives saves and future default updates propagate.
This commit is contained in:
@@ -91,26 +91,23 @@ export async function sendInvoiceEmail(
|
||||
(language === "en" ? DEFAULT_EMAIL_SUBJECT_EN : DEFAULT_EMAIL_SUBJECT_DE);
|
||||
const subject = renderTemplate(customSubject, vars, { html: false });
|
||||
|
||||
// Pick the default body variant for the invoice's payment state: orders that
|
||||
// are already settled (paid / refunded / voided) get a body WITHOUT the
|
||||
// Pick the body variant for the invoice's payment state: orders that are
|
||||
// already settled (paid / refunded / voided) get a body WITHOUT the
|
||||
// bank-transfer reference hint; outstanding orders (unpaid / partial) keep
|
||||
// it. Legacy rows have an empty paymentStatus → treated as unpaid.
|
||||
// A merchant-supplied custom template always wins over the defaults.
|
||||
// it. Legacy invoice rows have an empty paymentStatus → treated as unpaid.
|
||||
// Each variant has its own merchant-customisable field; empty falls back to
|
||||
// the built-in default for that variant.
|
||||
const isPaid =
|
||||
invoice.paymentStatus === "paid" ||
|
||||
invoice.paymentStatus === "refunded" ||
|
||||
invoice.paymentStatus === "voided";
|
||||
const defaultBody =
|
||||
language === "en"
|
||||
? isPaid
|
||||
? DEFAULT_EMAIL_BODY_EN_PAID
|
||||
: DEFAULT_EMAIL_BODY_EN_UNPAID
|
||||
: isPaid
|
||||
? DEFAULT_EMAIL_BODY_DE_PAID
|
||||
: DEFAULT_EMAIL_BODY_DE_UNPAID;
|
||||
const customBodyHtml =
|
||||
(language === "en" ? settings.emailBodyHtmlEn : settings.emailBodyHtmlDe) ||
|
||||
defaultBody;
|
||||
const customBodyHtml = isPaid
|
||||
? language === "en"
|
||||
? settings.emailBodyHtmlEnPaid || DEFAULT_EMAIL_BODY_EN_PAID
|
||||
: settings.emailBodyHtmlDePaid || DEFAULT_EMAIL_BODY_DE_PAID
|
||||
: language === "en"
|
||||
? settings.emailBodyHtmlEn || DEFAULT_EMAIL_BODY_EN_UNPAID
|
||||
: settings.emailBodyHtmlDe || DEFAULT_EMAIL_BODY_DE_UNPAID;
|
||||
const body = renderHtmlBody(renderTemplate(customBodyHtml, vars));
|
||||
|
||||
// If the rendered body references the inline logo, attach it.
|
||||
|
||||
Reference in New Issue
Block a user