@spree/docs 0.1.294 → 0.1.295
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -42,7 +42,8 @@ Each object's fields, and the fields of the objects nested in it.
|
|
|
42
42
|
|
|
43
43
|
### `store`
|
|
44
44
|
|
|
45
|
-
- `store`: `id`, `name`, `address`, `mail_from_address`, `default_currency`, `default_locale`, `url`, `support_email`, `logo_url`, `logo_width`
|
|
45
|
+
- `store`: `id`, `name`, `address`, `mail_from_address`, `default_currency`, `default_locale`, `url`, `support_email`, `logo_url`, `logo_width`, `branding`
|
|
46
|
+
- `store.branding`: `background_color`, `card_color`, `text_color`, `heading_color`, `accent_color` (empty unless the merchant set one), `link_color`, `button_color`, `button_text_color`, `button_border`, `font`, `font_family`, `heading_font_family`, `font_url` (a web font's stylesheet, empty for email-safe fonts)
|
|
46
47
|
|
|
47
48
|
### `order`
|
|
48
49
|
|
|
@@ -8,7 +8,7 @@ Every email Spree sends — order confirmations, shipping notices, password rese
|
|
|
8
8
|
|
|
9
9
|
To change an email, you copy its template into your app and edit it. Nothing else changes: Spree still picks the recipient, the language and the sender, and delivers the email through your [SMTP provider](../providers/emails.md).
|
|
10
10
|
|
|
11
|
-
> **NOTE:** Templates read plain data — the same fields the [Store API](../../api-reference/store-api/introduction.md) returns, plus what only an email needs — never Ruby objects. The same template can
|
|
11
|
+
> **NOTE:** Templates read plain data — the same fields the [Store API](../../api-reference/store-api/introduction.md) returns, plus what only an email needs — never Ruby objects. The same template can run outside Ruby, and merchants can edit customer emails safely from the dashboard.
|
|
12
12
|
|
|
13
13
|
## Where templates live
|
|
14
14
|
|
|
@@ -102,6 +102,73 @@ In development and test, a variable that does not exist raises an error instead
|
|
|
102
102
|
|
|
103
103
|
To look at every email with real data, open the mailer previews at `/rails/mailers` on your Spree server.
|
|
104
104
|
|
|
105
|
+
## Templates merchants edit in the dashboard
|
|
106
|
+
|
|
107
|
+
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.
|
|
108
|
+
|
|
109
|
+
A store's published template comes first, so the lookup for an editable email is:
|
|
110
|
+
|
|
111
|
+
1. the store's published template in the email's language
|
|
112
|
+
2. the store's published template for every language
|
|
113
|
+
3. your app's file
|
|
114
|
+
4. Spree's file
|
|
115
|
+
|
|
116
|
+
Your file stays the default the dashboard starts from and reverts to, so overriding a template in code and letting merchants edit it work together. When a Spree upgrade or a change to your file alters a default a merchant has customized, the dashboard tells them and shows what changed.
|
|
117
|
+
|
|
118
|
+
The same operations are open to integrations through the [Admin API](../../api-reference/admin-api/introduction.md), with the `email_templates` permission:
|
|
119
|
+
|
|
120
|
+
**Admin SDK:**
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const preview = await client.emailTemplates.preview('spree.order_mailer.confirm_email', {
|
|
124
|
+
body: '<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name }}!</mj-text></mj-column></mj-section>',
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
await client.emailTemplates.draft.update('spree.order_mailer.confirm_email', {
|
|
128
|
+
body: '<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name }}!</mj-text></mj-column></mj-section>',
|
|
129
|
+
})
|
|
130
|
+
await client.emailTemplates.publish('spree.order_mailer.confirm_email')
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**cURL:**
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
curl -X PUT https://your-store.com/api/v3/admin/email_templates/spree.order_mailer.confirm_email/draft \
|
|
137
|
+
-H "X-Spree-Api-Key: sk_xxx" -H "Content-Type: application/json" \
|
|
138
|
+
-d '{"body": "<mj-section><mj-column><mj-text>Thanks, {{ order.customer_name }}!</mj-text></mj-column></mj-section>"}'
|
|
139
|
+
|
|
140
|
+
curl -X POST https://your-store.com/api/v3/admin/email_templates/spree.order_mailer.confirm_email/publication \
|
|
141
|
+
-H "X-Spree-Api-Key: sk_xxx"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### Branding
|
|
146
|
+
|
|
147
|
+
Merchants set the colors and font of their customer emails in **Settings → Emails**, without touching a template. Templates read them from [`store.branding`](email-variables.md#store), and Spree's layout uses them throughout. If you override the layout or a template, read colors and fonts from `store.branding` rather than writing them in, so a store's branding keeps applying.
|
|
148
|
+
|
|
149
|
+
### Making your own customer email editable
|
|
150
|
+
|
|
151
|
+
A customer email your app adds can be edited like Spree's own. Register it with a class that builds the data its preview renders with:
|
|
152
|
+
|
|
153
|
+
```ruby server/config/initializers/spree.rb
|
|
154
|
+
Rails.application.config.after_initialize do
|
|
155
|
+
Spree.editable_email_templates.register(
|
|
156
|
+
'spree/review_mailer/request_email', kind: :email, sample: 'ReviewRequestSample'
|
|
157
|
+
)
|
|
158
|
+
end
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```ruby server/app/services/review_request_sample.rb
|
|
162
|
+
# Previews with the store's latest completed order, or the one the merchant picks.
|
|
163
|
+
class ReviewRequestSample < Spree::Emails::Samples::Order
|
|
164
|
+
def variables
|
|
165
|
+
{ order: super[:order], review_url: placeholder_url('reviews/new') }
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
A sample builds from the record the merchant picked, else the store's latest one; a store with none is told there is nothing to preview with yet. Pass placeholder URLs, never real tokens, and register only emails your customers receive.
|
|
171
|
+
|
|
105
172
|
## Your own mailers
|
|
106
173
|
|
|
107
174
|
A mailer that inherits `Spree::BaseMailer` and renders its own ERB views with `mail` keeps working. Spree wraps its HTML in the same layout as every other email, so it carries the store's logo, header and footer. The `spree/shared/mailer_hero` and `spree/shared/mailer_button` partials are still there for those views.
|