Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fixed CI and review feedback on the email template editor

Damian Legawiec09b8fc3d676d
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yaml
index f49dc070f4..c4b7fa2f74 100644
--- a/docs/api-reference/admin.yaml
+++ b/docs/api-reference/admin.yaml
@@ -7402,41 +7402,19 @@ paths:
application/json:
example:
data:
- - id: spree.admin_user_mailer.password_reset_email
- key: spree/admin_user_mailer/password_reset_email
- subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ - id: spree.order_mailer.confirm_email
+ key: spree/order_mailer/confirm_email
+ subject: Order {{ order.number }} confirmed
+ body: "<mj-section><mj-column><mj-text>Thanks for your order, {{
+ order.customer_name }}!</mj-text></mj-column></mj-section>\n"
language: any
customized_languages: []
kind: email
customized: false
published_at:
- default_subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- default_body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ default_subject: Order {{ order.number }} confirmed
+ default_body: "<mj-section><mj-column><mj-text>Thanks for your order,
+ {{ order.customer_name }}!</mj-text></mj-column></mj-section>\n"
default_changed: false
base_subject:
base_body:
@@ -7687,48 +7665,27 @@ paths:
content:
application/json:
example:
- id: spree.admin_user_mailer.password_reset_email
- key: spree/admin_user_mailer/password_reset_email
- subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ id: spree.order_mailer.confirm_email
+ key: spree/order_mailer/confirm_email
+ subject: Order {{ order.number }} confirmed
+ body: "<mj-section><mj-column><mj-text>Thanks for your order, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>\n"
language: any
customized_languages: []
kind: email
customized: false
published_at:
- default_subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- default_body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ default_subject: Order {{ order.number }} confirmed
+ default_body: "<mj-section><mj-column><mj-text>Thanks for your order,
+ {{ order.customer_name }}!</mj-text></mj-column></mj-section>\n"
default_changed: true
base_subject: Reset {{ store.name }}
base_body: "<mj-section><mj-column><mj-text>Default</mj-text></mj-column></mj-section>"
draft:
id: etdr_UkLWZg9DAJ
subject: Reset {{ store.name }}
- body: "<mj-section><mj-column><mj-text>Hi {{ user.first_name }}</mj-text></mj-column></mj-section>"
+ body: "<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>"
lock_version: 0
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
@@ -7806,41 +7763,19 @@ paths:
content:
application/json:
example:
- id: spree.admin_user_mailer.password_reset_email
- key: spree/admin_user_mailer/password_reset_email
- subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ id: spree.order_mailer.confirm_email
+ key: spree/order_mailer/confirm_email
+ subject: Order {{ order.number }} confirmed
+ body: "<mj-section><mj-column><mj-text>Thanks for your order, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>\n"
language: any
customized_languages: []
kind: email
customized: false
published_at:
- default_subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- default_body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ default_subject: Order {{ order.number }} confirmed
+ default_body: "<mj-section><mj-column><mj-text>Thanks for your order,
+ {{ order.customer_name }}!</mj-text></mj-column></mj-section>\n"
default_changed: false
base_subject:
base_body:
@@ -7912,48 +7847,27 @@ paths:
content:
application/json:
example:
- id: spree.admin_user_mailer.password_reset_email
- key: spree/admin_user_mailer/password_reset_email
- subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ id: spree.order_mailer.confirm_email
+ key: spree/order_mailer/confirm_email
+ subject: Order {{ order.number }} confirmed
+ body: "<mj-section><mj-column><mj-text>Thanks for your order, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>\n"
language: any
customized_languages: []
kind: email
customized: false
published_at:
- default_subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- default_body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ default_subject: Order {{ order.number }} confirmed
+ default_body: "<mj-section><mj-column><mj-text>Thanks for your order,
+ {{ order.customer_name }}!</mj-text></mj-column></mj-section>\n"
default_changed: false
base_subject:
base_body:
draft:
id: etdr_UkLWZg9DAJ
- subject: Reset your {{ store.name }} password
- body: "<mj-section><mj-column><mj-text>Hi {{ user.first_name }}</mj-text></mj-column></mj-section>"
+ subject: Your order {{ order.number }} is confirmed
+ body: "<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>"
lock_version: 0
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
@@ -7985,11 +7899,11 @@ paths:
example: any
subject:
type: string
- example: Reset your {{ store.name }} password
+ example: Your order {{ order.number }} is confirmed
body:
type: string
- example: "<mj-section><mj-column><mj-text>Hi {{ user.first_name
- }}</mj-text></mj-column></mj-section>"
+ example: "<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>"
lock_version:
type: integer
example: 0
@@ -8051,41 +7965,19 @@ paths:
content:
application/json:
example:
- id: spree.admin_user_mailer.password_reset_email
- key: spree/admin_user_mailer/password_reset_email
- subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ id: spree.order_mailer.confirm_email
+ key: spree/order_mailer/confirm_email
+ subject: Order {{ order.number }} confirmed
+ body: "<mj-section><mj-column><mj-text>Thanks for your order, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>\n"
language: any
customized_languages: []
kind: email
customized: false
published_at:
- default_subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- default_body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ default_subject: Order {{ order.number }} confirmed
+ default_body: "<mj-section><mj-column><mj-text>Thanks for your order,
+ {{ order.customer_name }}!</mj-text></mj-column></mj-section>\n"
default_changed: false
base_subject:
base_body:
@@ -8150,30 +8042,20 @@ paths:
content:
application/json:
example:
- id: spree.admin_user_mailer.password_reset_email
- key: spree/admin_user_mailer/password_reset_email
+ id: spree.order_mailer.confirm_email
+ key: spree/order_mailer/confirm_email
subject: Reset {{ store.name }}
- body: "<mj-section><mj-column><mj-text>Hi {{ user.first_name }}</mj-text></mj-column></mj-section>"
+ body: "<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>"
language: any
customized_languages:
- any
kind: email
customized: true
published_at: '2026-01-15T12:00:00Z'
- default_subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- default_body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ default_subject: Order {{ order.number }} confirmed
+ default_body: "<mj-section><mj-column><mj-text>Thanks for your order,
+ {{ order.customer_name }}!</mj-text></mj-column></mj-section>\n"
default_changed: true
base_subject: Reset {{ store.name }}
base_body: "<mj-section><mj-column><mj-text>Default</mj-text></mj-column></mj-section>"
@@ -8187,11 +8069,12 @@ paths:
example:
error:
code: email_template_invalid
- message: 'Liquid error (line 1): undefined variable nickname'
+ message: 'Liquid error (line 1): undefined variable nubmer'
details:
problems:
- - email: spree.admin_user_mailer.password_reset_email
- message: 'Liquid error (line 1): undefined variable nickname'
+ - email: spree.order_mailer.confirm_email
+ locale: any
+ message: 'Liquid error (line 1): undefined variable nubmer'
line: 1
schema:
"$ref": "#/components/schemas/ErrorResponse"
@@ -8371,8 +8254,8 @@ paths:
width=\"100%\"><tbody><tr><td style=\"vertical-align:top;padding:0;\"><table
border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\"
width=\"100%\"><tbody><tr><td align=\"center\" style=\"font-size:0px;padding:0;word-break:break-word;\"><div
- style=\"font-family:Inter, Helvetica, Arial, sans-serif;font-size:14px;line-height:1.6;text-align:center;color:#726A6A;\">Hi
- Ann</div></td></tr></tbody></table></td></tr></tbody></table></div><!--[if
+ style=\"font-family:Inter, Helvetica, Arial, sans-serif;font-size:14px;line-height:1.6;text-align:center;color:#726A6A;\">Thanks,
+ Ann Lee!</div></td></tr></tbody></table></td></tr></tbody></table></div><!--[if
mso | IE]></td><![endif]--><!--[if mso | IE]></tr></table><![endif]--></td></tr></tbody></table></div><!--[if
mso | IE]></td></tr></table><![endif]--><!--[if mso | IE]></td></tr></table><![endif]--></td></tr></tbody></table></div><!--[if
mso | IE]></td></tr></table><![endif]--><!--[if mso | IE]><table
@@ -8403,14 +8286,14 @@ paths:
text: |
Spree Test Store (http://www.example.com:3000)
- Hi Ann
+ Thanks, Ann Lee!
Spree Test Store (http://www.example.com:3000)
© 2026 Spree Test Store
- email_key: spree.admin_user_mailer.password_reset_email
+ email_key: spree.order_mailer.confirm_email
variables:
store:
id: store_UkLWZg9DAJ
@@ -8441,6 +8324,9 @@ paths:
user:
first_name: Ann
+ order:
+ number: R123456789
+ customer_name: Ann Lee
reset_url: http://www.example.com:3000/reset-password?token=preview
schema:
"$ref": "#/components/schemas/EmailTemplatePreview"
@@ -8455,11 +8341,11 @@ paths:
example: any
subject:
type: string
- example: Reset your {{ store.name }} password
+ example: Your order {{ order.number }} is confirmed
body:
type: string
- example: "<mj-section><mj-column><mj-text>Hi {{ user.first_name
- }}</mj-text></mj-column></mj-section>"
+ example: "<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>"
record_id:
type: string
example: or_m3Rp9wXz
@@ -8508,13 +8394,10 @@ paths:
- Email Templates
security:
- bearer_auth: []
- description: |-
+ description: |
Sends the template, rendered as the preview renders it, to the
signed-in admin, and never to another address: the sample data comes
from a real customer's records. Takes the same body as the preview.
-
-
- **Required scope:** `write_email_templates` (for API-key authentication).
x-codeSamples:
- lang: javascript
label: Spree Admin SDK
@@ -8526,7 +8409,8 @@ paths:
secretKey: 'sk_xxx',
})
- // Always sent to the signed-in admin.
+ // Sent to the signed-in admin, so this needs a client created with `jwtToken`;
+ // a secret key has no inbox and is refused.
const { sent_to } = await client.emailTemplates.sendTest('spree.order_mailer.confirm_email', {
body: '<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name }}!</mj-text></mj-column></mj-section>',
})
@@ -8739,8 +8623,8 @@ paths:
content:
application/json:
example:
- id: spree.admin_user_mailer.password_reset_email
- key: spree/admin_user_mailer/password_reset_email
+ id: spree.order_mailer.confirm_email
+ key: spree/order_mailer/confirm_email
subject: Reset {{ store.name }}
body: "<mj-section><mj-column><mj-text>Hello</mj-text></mj-column></mj-section>"
language: any
@@ -8749,27 +8633,17 @@ paths:
kind: email
customized: true
published_at: '2026-01-15T12:00:00Z'
- default_subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject'
- | t }}"
- default_body: |
- {% assign name = user.first_name | default: user.email %}
- <mj-section>
- <mj-column css-class="hero">
- <mj-text mj-class="heading">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-text>
- <mj-text mj-class="greeting">{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
- <mj-text mj-class="lead">{{ 'admin_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
- <mj-button href="{{ reset_url }}">{{ 'admin_user_mailer.password_reset_email.action' | t }}</mj-button>
- <mj-text mj-class="note">{{ 'admin_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
- <mj-text mj-class="note" padding="16px 0 0">{{ 'admin_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
- </mj-column>
- </mj-section>
+ default_subject: Order {{ order.number }} confirmed
+ default_body: "<mj-section><mj-column><mj-text>Thanks for your order,
+ {{ order.customer_name }}!</mj-text></mj-column></mj-section>\n"
default_changed: true
base_subject: Reset {{ store.name }}
base_body: "<mj-section><mj-column><mj-text>Default</mj-text></mj-column></mj-section>"
draft:
id: etdr_UkLWZg9DAJ
subject: Reset {{ store.name }}
- body: "<mj-section><mj-column><mj-text>Hi {{ user.first_name }}</mj-text></mj-column></mj-section>"
+ body: "<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name
+ }}!</mj-text></mj-column></mj-section>"
lock_version: 0
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
diff --git a/docs/developer/customization/emails.mdx b/docs/developer/customization/emails.mdx
index 4a5b86c9fa..3cc64ad924 100644
--- a/docs/developer/customization/emails.mdx
+++ b/docs/developer/customization/emails.mdx
@@ -106,7 +106,7 @@ To look at every email with real data, open the mailer previews at `/rails/maile
## Templates merchants edit in the dashboard
-Merchants can edit the emails their customers receive in **Settings → Emails → Templates**, along with the layout and the shared blocks in `spree/shared`. An edit is saved as a draft and goes live when published; publishing renders it with the store's own data first and refuses a template that does not render. Staff, store-owner and seller emails are not editable and always render from files.
+Merchants can edit the emails their customers receive in **Settings → Emails → Templates**, along with the layout and the shared blocks in `spree/shared`. An edit is saved as a draft and goes live when published; publishing renders it with the store's own data first and refuses a template that does not render. An email built from a record the store does not have yet, such as an order confirmation in a store with no orders, is checked for template syntax only. Staff, store-owner and seller emails are not editable and always render from files.
A store's published template comes first, so the lookup for an editable email is:
diff --git a/docs/plans/6.0-email-template-editor.md b/docs/plans/6.0-email-template-editor.md
index 2af088db7c..e09586799a 100644
--- a/docs/plans/6.0-email-template-editor.md
+++ b/docs/plans/6.0-email-template-editor.md
@@ -37,7 +37,7 @@ Every transactional email Spree sends renders from a Liquid template written in
- **The subject is a field of its own.** Files carry the subject as front matter; a saved template stores `subject` and `body` separately, which is the shape the front matter was chosen to map onto. The editor shows the subject as a text field above the code.
- **Email templates are their own permission resource** (`email_templates`), not part of `settings`. A template writes content every customer receives, including links, so the RBAC plan's rule for sensitive resources applies: a role can manage store settings without being able to change what customers are emailed.
- **Branding lives in store preferences** and reaches templates as `store.branding` variables that the layout's `<mj-attributes>` read. It is independent of any template's code, so reverting a template never loses the store's colors and fonts.
-- **Autocomplete reads a TypeScript manifest built on generated types; there is no variables API** (2026-10-01). Typelizer, added to `spree_emails`, generates TypeScript types for the email serializers (`EmailOrder`, `EmailOrderGroup`, `EmailFulfillment`, `EmailReturn`, the email store, …) into `@spree/admin-sdk`, and the existing pipeline turns them into Zod schemas. A hand-written manifest in the dashboard maps each editable email and shared block to the variables it receives and their schema; the editor walks the schemas to offer fields. The preview response also returns the data it rendered with, so autocomplete shows real example values at no extra cost.
+- **Autocomplete reads a TypeScript manifest built on generated types; there is no variables API** (2026-10-01). Typelizer, added to `spree_emails`, generates TypeScript types for the email serializers (`EmailOrder`, `EmailOrderGroup`, `EmailFulfillment`, `EmailReturn`, the email store, …) into `@spree/admin-sdk`. A hand-written manifest in the dashboard, typed against those types so a renamed field fails the typecheck, maps each editable email and shared block to the variables it receives. The editor offers those, plus the fields of the data the preview response returns, which also gives real example values at no extra cost. (The email types have no Zod schemas; see the decision on email data types below.)
- **Accepted trade-off:** the manifest's list of which variables each email receives is kept in step with its mailer by hand. Field types cannot drift, because they are generated. An extension adding a customer email registers its manifest entry through a dashboard plugin.
- **The template remembers the default it started from as text, not a digest** (2026-10-01). Drafts and published versions store `base_subject` and `base_body`. Comparing them with the current file tells the editor the default changed, and keeping the text lets it show what changed side by side. There is no separate endpoint for the comparison: reading a template returns the current default and, when it changed, the base. A merchant who has reviewed the change keeps their version by saving the draft with `rebase`. Rejected: a SHA-256 digest, which says that something changed but not what.
diff --git a/docs/user/settings/emails.mdx b/docs/user/settings/emails.mdx
index 73a64dcef5..0b7a9b65a5 100644
--- a/docs/user/settings/emails.mdx
+++ b/docs/user/settings/emails.mdx
@@ -75,7 +75,7 @@ Click **Send test email** to receive the email at your own address before publis
### Publishing
-**Publish** makes the draft what customers receive from the next email on. Spree first fills the template in with your store's data, and refuses to publish one that does not work, such as a misspelled placeholder, with the line to fix. When you publish the layout or a shared block, Spree checks every customer email that uses it.
+**Publish** makes the draft what customers receive from the next email on. Spree first fills the template in with your store's data, and refuses to publish one that does not work, such as a misspelled placeholder, with the line to fix. When you publish the layout or a shared block, Spree checks every customer email that uses it. If your store has nothing to fill an email in with yet, such as no orders for the order confirmation, Spree can only check the template's spelling and structure, so send yourself a test email once you have an order.
### Languages
diff --git a/packages/admin-sdk/examples/email-templates/send-test.ts b/packages/admin-sdk/examples/email-templates/send-test.ts
index 8be2c3c839..ff8ef4d984 100644
--- a/packages/admin-sdk/examples/email-templates/send-test.ts
+++ b/packages/admin-sdk/examples/email-templates/send-test.ts
@@ -2,11 +2,12 @@ import { createAdminClient } from '@spree/admin-sdk'
const client = createAdminClient({
baseUrl: 'https://your-store.com',
- secretKey: 'sk_xxx',
+ jwtToken: 'eyJhbGciOi...',
})
// region:example
-// Always sent to the signed-in admin.
+// Sent to the signed-in admin, so this needs a client created with `jwtToken`;
+// a secret key has no inbox and is refused.
const { sent_to } = await client.emailTemplates.sendTest('spree.order_mailer.confirm_email', {
body: '<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name }}!</mj-text></mj-column></mj-section>',
})
diff --git a/spree/api/app/controllers/concerns/spree/api/v3/admin/email_template_lookup.rb b/spree/api/app/controllers/concerns/spree/api/v3/admin/email_template_lookup.rb
index 184fa26228..df652dc09e 100644
--- a/spree/api/app/controllers/concerns/spree/api/v3/admin/email_template_lookup.rb
+++ b/spree/api/app/controllers/concerns/spree/api/v3/admin/email_template_lookup.rb
@@ -21,7 +21,7 @@ module Spree
attr_reader :email_template
def load_email_template
- @email_template = Spree::EmailTemplates::Entry.find(
+ @email_template = Spree::EmailTemplates::Entry.for_id(
current_store, params[:email_template_id] || params[:id], locale: language
)
end
diff --git a/spree/api/spec/integration/spree/api/v3/admin/email_templates_spec.rb b/spree/api/spec/integration/spree/api/v3/admin/email_templates_spec.rb
index 36c3bbbaee..0a5be17995 100644
--- a/spree/api/spec/integration/spree/api/v3/admin/email_templates_spec.rb
+++ b/spree/api/spec/integration/spree/api/v3/admin/email_templates_spec.rb
@@ -6,11 +6,29 @@ RSpec.describe 'Admin Email Templates API', type: :request, swagger_doc: 'api-re
include_context 'API v3 Admin'
include_context 'with an editable email template'
+ # The test app ships no customer emails, so the reference documents an
+ # order confirmation from a fixture file.
+ let(:editable_key) { 'spree/order_mailer/confirm_email' }
+ let(:fixture_path) { Rails.root.join('app/views/spree/order_mailer/confirm_email.liquid') }
+
+ around do |example|
+ FileUtils.mkdir_p(fixture_path.dirname)
+ File.write(fixture_path, <<~LIQUID)
+ ---
+ subject: "Order {{ order.number }} confirmed"
+ ---
+ <mj-section><mj-column><mj-text>Thanks for your order, {{ order.customer_name }}!</mj-text></mj-column></mj-section>
+ LIQUID
+ example.run
+ ensure
+ FileUtils.rm_rf(fixture_path.dirname)
+ end
+
let(:Authorization) { "Bearer #{admin_jwt_token}" }
let(:'x-spree-api-key') { secret_api_key.plaintext_token }
let(:id) { editable_key.tr('/', '.') }
let(:email_template_id) { id }
- let(:body_mjml) { '<mj-section><mj-column><mj-text>Hi {{ user.first_name }}</mj-text></mj-column></mj-section>' }
+ let(:body_mjml) { '<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name }}!</mj-text></mj-column></mj-section>' }
shared_context 'with admin auth parameters' do
parameter name: 'x-spree-api-key', in: :header, type: :string, required: true
@@ -147,15 +165,15 @@ RSpec.describe 'Admin Email Templates API', type: :request, swagger_doc: 'api-re
type: :object,
properties: {
language: { type: :string, example: 'any' },
- subject: { type: :string, example: 'Reset your {{ store.name }} password' },
- body: { type: :string, example: '<mj-section><mj-column><mj-text>Hi {{ user.first_name }}</mj-text></mj-column></mj-section>' },
+ subject: { type: :string, example: 'Your order {{ order.number }} is confirmed' },
+ body: { type: :string, example: '<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name }}!</mj-text></mj-column></mj-section>' },
lock_version: { type: :integer, example: 0 },
rebase: { type: :boolean, description: "Marks the draft as based on Spree's current default, after reviewing what changed in it" }
}
}
response '200', 'draft saved' do
- let(:body) { { subject: 'Reset your {{ store.name }} password', body: body_mjml } }
+ let(:body) { { subject: 'Your order {{ order.number }} is confirmed', body: body_mjml } }
schema '$ref' => '#/components/schemas/EmailTemplate'
@@ -247,13 +265,13 @@ RSpec.describe 'Admin Email Templates API', type: :request, swagger_doc: 'api-re
response '422', 'the draft does not render' do
let(:body) { {} }
- before { create(:email_template_draft, store: store, key: editable_key, body: '{{ user.nickname }}') }
+ before { create(:email_template_draft, store: store, key: editable_key, body: '{{ order.nubmer }}') }
schema '$ref' => '#/components/schemas/ErrorResponse'
run_test! do |response|
problems = JSON.parse(response.body)['error']['details']['problems']
- expect(problems.first['message']).to include('nickname')
+ expect(problems.first['message']).to include('nubmer')
end
end
end
@@ -285,8 +303,8 @@ RSpec.describe 'Admin Email Templates API', type: :request, swagger_doc: 'api-re
type: :object,
properties: {
language: { type: :string, example: 'any' },
- subject: { type: :string, example: 'Reset your {{ store.name }} password' },
- body: { type: :string, example: '<mj-section><mj-column><mj-text>Hi {{ user.first_name }}</mj-text></mj-column></mj-section>' },
+ subject: { type: :string, example: 'Your order {{ order.number }} is confirmed' },
+ body: { type: :string, example: '<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name }}!</mj-text></mj-column></mj-section>' },
record_id: { type: :string, example: 'or_m3Rp9wXz', description: 'The record to build sample data from' },
email_key: { type: :string, example: 'spree.order_mailer.confirm_email', description: 'For the layout or a partial, the email to show it in' },
branding: {
@@ -310,7 +328,7 @@ RSpec.describe 'Admin Email Templates API', type: :request, swagger_doc: 'api-re
schema '$ref' => '#/components/schemas/EmailTemplatePreview'
run_test! do |response|
- expect(JSON.parse(response.body)['html']).to include('Hi Ann')
+ expect(JSON.parse(response.body)['html']).to include('Thanks, Ann Lee!')
end
end
end
@@ -330,7 +348,6 @@ RSpec.describe 'Admin Email Templates API', type: :request, swagger_doc: 'api-re
signed-in admin, and never to another address: the sample data comes
from a real customer's records. Takes the same body as the preview.
DESC
- admin_scope :write, :email_templates
admin_sdk_example 'email-templates/send-test'
diff --git a/spree/core/app/models/concerns/spree/admin_user_methods.rb b/spree/core/app/models/concerns/spree/admin_user_methods.rb
index a9bf96a8c6..b214dc0c98 100644
--- a/spree/core/app/models/concerns/spree/admin_user_methods.rb
+++ b/spree/core/app/models/concerns/spree/admin_user_methods.rb
@@ -136,10 +136,14 @@ module Spree
# @param model [Class]
# @param name [Symbol] the acted_by association
def clear_actor(model, name)
+ columns = Spree::ActedBy.columns_for(name, nil)
+ # Append-only tables (revisions) have no updated_at to stamp.
+ columns = columns.merge(updated_at: Time.current) if model.column_names.include?('updated_at')
+
model.
where(:"#{name}_id" => id).
where(:"#{name}_type" => [self.class.polymorphic_name, nil]).
- update_all(Spree::ActedBy.columns_for(name, nil).merge(updated_at: Time.current))
+ update_all(columns)
end
end
end
diff --git a/spree/core/app/models/spree/email_templates/entry.rb b/spree/core/app/models/spree/email_templates/entry.rb
index f2ba81f431..a0f9d9cca4 100644
--- a/spree/core/app/models/spree/email_templates/entry.rb
+++ b/spree/core/app/models/spree/email_templates/entry.rb
@@ -34,7 +34,7 @@ module Spree
# @param locale [String]
# @return [Spree::EmailTemplates::Entry]
# @raise [ActiveRecord::RecordNotFound] when no editable template has that id
- def self.find(store, id, locale: Spree::EmailTemplate::ANY_LOCALE)
+ def self.for_id(store, id, locale: Spree::EmailTemplate::ANY_LOCALE)
definition = Spree.editable_email_templates[id.to_s.tr('.', '/')]
raise ActiveRecord::RecordNotFound, "Couldn't find email template #{id}" unless definition
diff --git a/spree/core/lib/spree/testing_support/editable_email_templates.rb b/spree/core/lib/spree/testing_support/editable_email_templates.rb
index ddbe39cc74..779c9f7d85 100644
--- a/spree/core/lib/spree/testing_support/editable_email_templates.rb
+++ b/spree/core/lib/spree/testing_support/editable_email_templates.rb
@@ -24,6 +24,7 @@ module Spree
def variables
{
user: { 'first_name' => 'Ann', 'email' => '[email protected]' },
+ order: { 'number' => 'R123456789', 'customer_name' => 'Ann Lee' },
reset_url: "#{@store.storefront_url}/reset-password?token=preview"
}
end
@@ -43,9 +44,12 @@ RSpec.shared_context 'with an editable email template' do
previous_layout = registry['layouts/spree/base_mailer']
registry.register(editable_key, kind: :email, sample: 'Spree::TestingSupport::EmailTemplateSample')
registry.register('layouts/spree/base_mailer', kind: :layout)
- example.run
- ensure
- previous ? registry.register(previous.key, kind: previous.kind, sample: previous.sample) : registry.delete(editable_key)
- previous_layout ? registry.register(previous_layout.key, kind: :layout) : registry.delete('layouts/spree/base_mailer')
+
+ begin
+ example.run
+ ensure
+ previous ? registry.register(previous.key, kind: previous.kind, sample: previous.sample) : registry.delete(editable_key)
+ previous_layout ? registry.register(previous_layout.key, kind: :layout) : registry.delete('layouts/spree/base_mailer')
+ end
end
end