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.

Moved transactional emails to Liquid and MJML templates (V-3720) (#14772)

Damian Legawiecaa30af47691e
diff --git a/CLAUDE.md b/CLAUDE.md
index faf9d9147b..f81223907d 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -422,6 +422,17 @@ end
For new models, add `publishes_lifecycle_events` concern and create an event serializer.
+### Emails (Liquid + MJML)
+
+Every email renders from a Liquid template written in MJML, never ERB. See `docs/plans/6.0-liquid-mjml-emails.md` and `docs/developer/customization/emails.mdx`.
+
+- **Template** lives at the mailer action's view path: `app/views/spree/<mailer>/<action>.liquid`. That path is its public key, so renaming a mailer or action is a breaking change. The subject goes in YAML front matter; the plain-text part is generated from the HTML (add `<action>.text.liquid` only to hand-write it). Layout is `layouts/spree/base_mailer.liquid`; shared blocks are `spree/shared/_*.liquid`, pulled in with `{% render 'spree/shared/line_item', item: item %}`.
+- **Mailer** inherits `Spree::BaseMailer`, sets `@current_store`, wraps the send in `with_store_locale(store, locale)`, and calls `mail_template({ order: email_data(@order, Spree::Emails::OrderSerializer), resend: resend }, to: ...)`. Keep the mailer's guards (recipients, status checks) as they are.
+- **Data comes from serializers, never models.** `email_data` turns a record into the JSON a template reads. Customer emails extend the Store API serializers (`spree/emails/app/serializers/spree/emails/`); staff emails use core ones (`spree/core/app/serializers/spree/emails/`) so they work without `spree_api`. Add email-only fields there, not to the public Store serializers. **Never serialize a token**: build reset, invitation, download and payment URLs in the mailer and pass them as their own variable.
+- **In templates**: output is HTML-escaped automatically (`| raw` only for HTML sanitized on write). Filters: `money`, `money_with_currency`, `date` (store time zone), `t` (Spree translation keys, so one template serves every language). An unknown variable raises in development and test.
+- **When you add or change an email**: if customers receive it, update `docs/developer/customization/email-variables.mdx` by hand with its variables, add it to `spree/emails/spec/mailers/spree/rendered_emails_spec.rb`, and give it a mailer preview (shown at `/rails/mailers` in development) in `spree/emails/lib/spree/emails/previews/` or, for staff emails, `spree/core/lib/spree/core/previews/`.
+- **Don't** add ERB email views, mailer view helpers, or model calls from templates. Apps' own mailers that call `mail` with ERB views still work: `layouts/spree/base_mailer.html.erb` wraps them in the Liquid layout.
+
### API Authentication
Four credential types, each with its own header and authorization model:
diff --git a/docs/developer/customization/email-variables.mdx b/docs/developer/customization/email-variables.mdx
new file mode 100644
index 0000000000..af873c4f4d
--- /dev/null
+++ b/docs/developer/customization/email-variables.mdx
@@ -0,0 +1,115 @@
+---
+title: Email Template Variables
+sidebarTitle: Template Variables
+description: Every variable the Liquid templates of customer emails receive, email by email.
+---
+
+These are the emails your customers receive. Every one of their templates receives `store` and `locale`, plus the variables listed for it below. Use these names exactly: a variable not listed here does not exist, and in development and test it raises an error. See [Email Templates](/developer/customization/emails) for how to override a template.
+
+## Emails
+
+| Template | Variables |
+| --- | --- |
+| `spree/order_mailer/confirm_email` | `order`, `resend` |
+| `spree/order_mailer/cancel_email` | `order`, `resend` |
+| `spree/order_mailer/payment_link_email` | `order`, `payment_url` |
+| `spree/order_group_mailer/confirm_email` | `order_group`, `resend` |
+| `spree/fulfillment_mailer/fulfilled_email` | `fulfillment`, `order`, `resend` |
+| `spree/return_mailer/refunded_email` | `return`, `order`, `resend` |
+| `spree/digital_asset_mailer/files_ready_email` | `order`, `downloads`, `resend` |
+| `spree/customer_mailer/password_reset_email` | `customer`, `reset_url` |
+| `spree/customer_mailer/data_export_email` | `download_url`, `expires_at` |
+| `spree/newsletter_mailer/email_confirmation` | `confirmation_url` |
+| `spree/company_mailer/invitation_email` | `company`, `accept_url` |
+
+## Values
+
+| Variable | What it holds |
+| --- | --- |
+| `resend` | True when staff re-sent the email. |
+| `locale` | The language the email renders in, e.g. `en`. |
+| `payment_url` | Where the customer pays for the order. |
+| `reset_url` | The password reset link, carrying its token. |
+| `accept_url` | The link that accepts the invitation, carrying its token. |
+| `confirmation_url` | The link that confirms the subscription, carrying its token. |
+| `download_url` | The signed link to the customer's data export. |
+| `expires_at` | When the data export link stops working. |
+| `downloads` | Each file bought: `filename`, `url` (carrying its token) and `expires_at`. |
+
+## Objects
+
+Each object's fields, and the fields of the objects nested in it.
+
+### `store`
+
+- `store`: `id`, `name`, `address`, `mail_from_address`, `default_currency`, `default_locale`, `url`, `support_email`, `logo_url`, `logo_width`
+
+### `order`
+
+- `order`: `id`, `market_id`, `withdrawal_period_ends_at`, `within_withdrawal_period`, `cart_id`, `channel_id`, `company_id`, `company_name`, `po_document_filename`, `po_document_byte_size`, `number`, `email`, `customer_note`, `po_number`, `currency`, `locale`, `total_quantity`, `coupon_code`, `fulfillment_status`, `payment_status`, `completed_at`, `item_total`, `display_item_total`, `adjustment_total`, `display_adjustment_total`, `discount_total`, `display_discount_total`, `tax_total`, `display_tax_total`, `included_tax_total`, `display_included_tax_total`, `additional_tax_total`, `display_additional_tax_total`, `total`, `display_total`, `gift_card_total`, `display_gift_card_total`, `amount_due`, `display_amount_due`, `delivery_total`, `display_delivery_total`, `fee_total`, `display_fee_total`, `store_credit_total`, `display_store_credit_total`, `covered_by_store_credit`, `customer_name`, `display_total_minus_store_credits`
+- `order.discounts`: `id`, `promotion_id`, `name`, `description`, `code`, `amount`, `display_amount`
+- `order.fees`: `id`, `label`, `kind`, `line_item_id`, `fulfillment_id`, `amount`, `display_amount`
+- `order.items`: `id`, `variant_id`, `seller_id`, `preorder`, `preorder_ships_at`, `quantity`, `currency`, `name`, `slug`, `options_text`, `price`, `display_price`, `total`, `display_total`, `adjustment_total`, `display_adjustment_total`, `additional_tax_total`, `display_additional_tax_total`, `included_tax_total`, `display_included_tax_total`, `discount_total`, `display_discount_total`, `pre_tax_amount`, `display_pre_tax_amount`, `discounted_amount`, `display_discounted_amount`, `display_compare_at_amount`, `compare_at_amount`, `url`, `image_url`, `sku`, `display_amount`
+- `order.items.option_values`: `id`, `option_type_id`, `name`, `label`, `position`, `color_code`, `option_type_name`, `option_type_label`, `image_url`
+- `order.fulfillments`: `id`, `number`, `tracking`, `tracking_url`, `pickup_point_data`, `selected_delivery_rate_id`, `unpriced`, `cost`, `display_cost`, `total`, `display_total`, `discount_total`, `display_discount_total`, `additional_tax_total`, `display_additional_tax_total`, `included_tax_total`, `display_included_tax_total`, `tax_total`, `display_tax_total`, `status`, `fulfillment_type`, `fulfilled_at`, `delivered_at`, `items`
+- `order.fulfillments.deliveries`: `id`, `tracking_number`, `carrier`, `carrier_name`, `service`, `status`, `tracking_url`, `estimated_delivery_at`, `delivered_at`
+- `order.fulfillments.delivery_method`: `id`, `name`, `code`, `estimated_transit_business_days_min`, `estimated_transit_business_days_max`, `digital`, `pickup`, `pickup_point`
+- `order.fulfillments.stock_location`: `id`, `name`, `address1`, `city`, `zipcode`, `country_code`, `country_name`, `state_code`, `state_text`, `pickup_ready_in_minutes`, `pickup_instructions`
+- `order.fulfillments.delivery_rates`: `id`, `delivery_method_id`, `name`, `selected`, `cost`, `total`, `additional_tax_total`, `included_tax_total`, `tax_total`, `carrier`, `service_level`, `estimated_delivery_date`, `unpriced`, `display_cost`, `display_total`, `display_additional_tax_total`, `display_included_tax_total`, `display_tax_total`
+- `order.payments`: `id`, `payment_method_id`, `response_code`, `number`, `status`, `amount`, `display_amount`, `source_type`, `source_id`, `source`
+- `order.payments.payment_method`: `id`, `name`, `description`, `type`, `session_required`, `source_required`
+- `order.billing_address`: `id`, `label`, `first_name`, `last_name`, `full_name`, `address1`, `address2`, `postal_code`, `city`, `phone`, `company`, `country_name`, `country_code`, `state_text`, `state_code`, `quick_checkout`, `is_default_billing`, `is_default_shipping`, `state_abbr`, `country_iso`, `state_name`
+- `order.shipping_address`: `id`, `label`, `first_name`, `last_name`, `full_name`, `address1`, `address2`, `postal_code`, `city`, `phone`, `company`, `country_name`, `country_code`, `state_text`, `state_code`, `quick_checkout`, `is_default_billing`, `is_default_shipping`, `state_abbr`, `country_iso`, `state_name`
+- `order.gift_card`: `id`, `code`, `status`, `currency`, `amount`, `amount_used`, `amount_authorized`, `amount_remaining`, `display_amount`, `display_amount_used`, `display_amount_remaining`, `expires_at`, `redeemed_at`, `expired`, `active`
+- `order.market`: `id`, `name`, `currency`, `default_locale`, `tax_inclusive`, `default`, `country_codes`, `country_isos`, `supported_locales`
+- `order.promotion_discounts`: `label`, `display_amount`, `amount`
+- `order.manual_discounts`: `label`, `display_amount`, `amount`
+- `order.fee_lines`: `label`, `display_amount`, `amount`
+- `order.delivery_lines`: `label`, `display_amount`, `amount`
+
+### `order_group`
+
+- `order_group`: `id`, `number`, `email`, `currency`, `total`, `display_total`, `item_total`, `display_item_total`, `fulfillment_status`, `payment_status`, `completed_at`, `customer_name`, `display_total_minus_store_credits`, `po_number`, `order_count`, `display_delivery_total`, `delivery_total`, `additional_tax_total`, `display_additional_tax_total`, `gift_card_total`, `display_gift_card_total`
+- `order_group.billing_address`: `id`, `label`, `first_name`, `last_name`, `full_name`, `address1`, `address2`, `postal_code`, `city`, `phone`, `company`, `country_name`, `country_code`, `state_text`, `state_code`, `quick_checkout`, `is_default_billing`, `is_default_shipping`, `state_abbr`, `country_iso`, `state_name`
+- `order_group.shipping_address`: `id`, `label`, `first_name`, `last_name`, `full_name`, `address1`, `address2`, `postal_code`, `city`, `phone`, `company`, `country_name`, `country_code`, `state_text`, `state_code`, `quick_checkout`, `is_default_billing`, `is_default_shipping`, `state_abbr`, `country_iso`, `state_name`
+- `order_group.items`: `id`, `variant_id`, `seller_id`, `preorder`, `preorder_ships_at`, `quantity`, `currency`, `name`, `slug`, `options_text`, `price`, `display_price`, `total`, `display_total`, `adjustment_total`, `display_adjustment_total`, `additional_tax_total`, `display_additional_tax_total`, `included_tax_total`, `display_included_tax_total`, `discount_total`, `display_discount_total`, `pre_tax_amount`, `display_pre_tax_amount`, `discounted_amount`, `display_discounted_amount`, `display_compare_at_amount`, `compare_at_amount`, `url`, `image_url`, `sku`, `display_amount`
+- `order_group.items.option_values`: `id`, `option_type_id`, `name`, `label`, `position`, `color_code`, `option_type_name`, `option_type_label`, `image_url`
+- `order_group.promotion_discounts`: `label`, `display_amount`, `amount`
+- `order_group.manual_discounts`: `label`, `display_amount`, `amount`
+- `order_group.fee_lines`: `label`, `display_amount`, `amount`
+- `order_group.fulfillment_groups`: `name`, `display_cost`, `seller_names`
+- `order_group.fulfillment_groups.items`: `id`, `url`, `image_url`, `name`, `quantity`, `sku`, `options_text`, `display_price`, `display_amount`
+- `order_group.unfulfilled_items`: `id`, `variant_id`, `seller_id`, `preorder`, `preorder_ships_at`, `quantity`, `currency`, `name`, `slug`, `options_text`, `price`, `display_price`, `total`, `display_total`, `adjustment_total`, `display_adjustment_total`, `additional_tax_total`, `display_additional_tax_total`, `included_tax_total`, `display_included_tax_total`, `discount_total`, `display_discount_total`, `pre_tax_amount`, `display_pre_tax_amount`, `discounted_amount`, `display_discounted_amount`, `display_compare_at_amount`, `compare_at_amount`, `url`, `image_url`, `sku`, `display_amount`
+- `order_group.unfulfilled_items.option_values`: `id`, `option_type_id`, `name`, `label`, `position`, `color_code`, `option_type_name`, `option_type_label`, `image_url`
+- `order_group.delivery_lines`: `label`, `display_amount`, `amount`
+
+### `fulfillment`
+
+- `fulfillment`: `id`, `number`, `tracking`, `tracking_url`, `pickup_point_data`, `selected_delivery_rate_id`, `unpriced`, `cost`, `display_cost`, `total`, `display_total`, `discount_total`, `display_discount_total`, `additional_tax_total`, `display_additional_tax_total`, `included_tax_total`, `display_included_tax_total`, `tax_total`, `display_tax_total`, `status`, `fulfillment_type`, `fulfilled_at`, `delivered_at`, `items`, `delivery_method_name`
+- `fulfillment.deliveries`: `id`, `tracking_number`, `carrier`, `carrier_name`, `service`, `status`, `tracking_url`, `estimated_delivery_at`, `delivered_at`
+- `fulfillment.delivery_method`: `id`, `name`, `code`, `estimated_transit_business_days_min`, `estimated_transit_business_days_max`, `digital`, `pickup`, `pickup_point`
+- `fulfillment.stock_location`: `id`, `name`, `address1`, `city`, `zipcode`, `country_code`, `country_name`, `state_code`, `state_text`, `pickup_ready_in_minutes`, `pickup_instructions`
+- `fulfillment.delivery_rates`: `id`, `delivery_method_id`, `name`, `selected`, `cost`, `total`, `additional_tax_total`, `included_tax_total`, `tax_total`, `carrier`, `service_level`, `estimated_delivery_date`, `unpriced`, `display_cost`, `display_total`, `display_additional_tax_total`, `display_included_tax_total`, `display_tax_total`
+- `fulfillment.delivery_rates.freight_summary`: `total_units`, `total_cartons`, `total_pallets`, `total_volume`, `total_weight`, `complete`
+- `fulfillment.delivery_rates.delivery_method`: `id`, `name`, `code`, `estimated_transit_business_days_min`, `estimated_transit_business_days_max`, `digital`, `pickup`, `pickup_point`
+- `fulfillment.manifest_items`: `id`, `url`, `image_url`, `name`, `quantity`, `sku`, `options_text`, `display_price`, `display_amount`
+
+### `return`
+
+- `return`: `id`, `number`, `status`, `order_id`, `reason_id`, `refund_total`, `display_refund_total`, `approved_at`, `received_at`, `refunded_at`, `canceled_at`, `display_refunded_total`
+- `return.returned_items`: `id`, `variant_id`, `seller_id`, `preorder`, `preorder_ships_at`, `quantity`, `currency`, `name`, `slug`, `options_text`, `price`, `display_price`, `total`, `display_total`, `adjustment_total`, `display_adjustment_total`, `additional_tax_total`, `display_additional_tax_total`, `included_tax_total`, `display_included_tax_total`, `discount_total`, `display_discount_total`, `pre_tax_amount`, `display_pre_tax_amount`, `discounted_amount`, `display_discounted_amount`, `display_compare_at_amount`, `compare_at_amount`, `url`, `image_url`, `sku`, `display_amount`
+- `return.returned_items.option_values`: `id`, `option_type_id`, `name`, `label`, `position`, `color_code`, `option_type_name`, `option_type_label`, `image_url`
+
+### `customer`
+
+- `customer`: `id`, `email`, `first_name`, `last_name`, `phone`, `accepts_email_marketing`, `email_marketing_consent_updated_at`, `full_name`, `available_store_credit_total`, `display_available_store_credit_total`
+- `customer.addresses`: `id`, `label`, `first_name`, `last_name`, `full_name`, `address1`, `address2`, `postal_code`, `city`, `phone`, `company`, `country_name`, `country_code`, `state_text`, `state_code`, `quick_checkout`, `is_default_billing`, `is_default_shipping`, `state_abbr`, `country_iso`, `state_name`
+- `customer.default_billing_address`: `id`, `label`, `first_name`, `last_name`, `full_name`, `address1`, `address2`, `postal_code`, `city`, `phone`, `company`, `country_name`, `country_code`, `state_text`, `state_code`, `quick_checkout`, `is_default_billing`, `is_default_shipping`, `state_abbr`, `country_iso`, `state_name`
+- `customer.default_shipping_address`: `id`, `label`, `first_name`, `last_name`, `full_name`, `address1`, `address2`, `postal_code`, `city`, `phone`, `company`, `country_name`, `country_code`, `state_text`, `state_code`, `quick_checkout`, `is_default_billing`, `is_default_shipping`, `state_abbr`, `country_iso`, `state_name`
+- `customer.newsletter_subscriber`: `id`, `email`, `created_at`, `updated_at`, `verified`, `verified_at`, `customer_id`
+- `customer.customer_groups`: `id`, `name`
+
+### `company`
+
+- `company`: `id`, `name`, `kind`, `po_number_required`, `parent_id`, `ancestors`
+
diff --git a/docs/developer/customization/emails.mdx b/docs/developer/customization/emails.mdx
new file mode 100644
index 0000000000..2af4919e19
--- /dev/null
+++ b/docs/developer/customization/emails.mdx
@@ -0,0 +1,134 @@
+---
+title: Email Templates
+sidebarTitle: Emails
+description: Change what Spree's transactional emails say and look like, with Liquid templates written in MJML.
+---
+
+Every email Spree sends — order confirmations, shipping notices, password resets, staff invitations — renders from a **Liquid** template written in **MJML**. Liquid fills in the data; MJML turns a dozen layout tags into the nested tables, inline styles and Outlook workarounds that email clients need, and makes the email stack on phones.
+
+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](/developer/providers/emails).
+
+<Note>
+ Templates read plain data — the same fields the [Store API](/api-reference/store-api/introduction) returns, plus what only an email needs — never Ruby objects. The same template can later run outside Ruby, and merchants will be able to edit templates safely from the dashboard.
+</Note>
+
+## Where templates live
+
+A template sits at its email's path with a `.liquid` extension. To override one, create the file at the same path in your app:
+
+| Email | Template |
+| --- | --- |
+| Order confirmation | `server/app/views/spree/order_mailer/confirm_email.liquid` |
+| Shipping notification | `server/app/views/spree/fulfillment_mailer/fulfilled_email.liquid` |
+| Customer password reset | `server/app/views/spree/customer_mailer/password_reset_email.liquid` |
+| The layout around every email | `server/app/views/layouts/spree/base_mailer.liquid` |
+
+The path is also the template's name, for example `spree/order_mailer/confirm_email`. [Email Template Variables](/developer/customization/email-variables) lists every customer email's template and the data it receives.
+
+Start from Spree's own template rather than a blank file: customer emails are in [`spree/emails/app/views`](https://github.com/spree/spree/tree/main/spree/emails/app/views/spree) and staff emails and the layout in [`spree/core/app/views`](https://github.com/spree/spree/tree/main/spree/core/app/views) on GitHub.
+
+Your file wins as soon as it exists, and edits to it show on the next email without a restart. There is nothing to register. The one exception: Rails only reads `server/app/views` if the folder existed when the app started, so restart once after creating that folder. API-only apps often start without it.
+
+## Anatomy of a template
+
+```liquid server/app/views/spree/order_mailer/confirm_email.liquid
+---
+subject: "{{ store.name }} {{ 'order_mailer.confirm_email.subject' | t }} #{{ order.number }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">Thanks for your order!</mj-text>
+ <mj-text mj-class="greeting">Hi {{ order.customer_name }},</mj-text>
+ <mj-button href="{{ store.url }}/account/orders/{{ order.number }}">View your order</mj-button>
+ </mj-column>
+</mj-section>
+{% assign heading = 'order_mailer.confirm_email.order_summary' | t: number: order.number %}
+{% render 'spree/shared/order_summary', heading: heading, purchase: order, items: order.items, totals: true %}
+```
+
+- **The subject** is the `subject` line at the top, and it is Liquid too.
+- **The body** is a list of MJML sections. The layout wraps it with the store's logo and footer.
+- **Copy** either comes from Spree's translations through the `t` filter, which keeps one template working in every language, or is written straight into the template for a single-language store.
+
+The layout defines named styles you can use through `mj-class`: `heading`, `greeting`, `lead`, `note`, `section-heading` and `body`. For the MJML tags themselves, see the [MJML documentation](https://documentation.mjml.io).
+
+## Partials
+
+Pull a shared piece in with `{% render %}`. The name maps to a file with a leading underscore, as Rails partials do: `'spree/shared/line_item'` is `app/views/spree/shared/_line_item.liquid`. A partial only sees the values you pass it.
+
+| Partial | Arguments | What it renders |
+| --- | --- | --- |
+| `spree/shared/order_summary` | `heading`, `purchase`, `items`, `totals` | A headed list of purchased items, with the order's totals when `totals` is true |
+| `spree/shared/line_item` | `item` | One purchased item: thumbnail, name, options, quantity and amount |
+| `spree/shared/purchase_totals` | `purchase` | Subtotal, discounts, delivery, tax, gift card, fees and total |
+| `spree/shared/fulfillment_group` | `group`, `position`, `count` | One parcel of a multi-seller purchase |
+| `spree/shared/summary_row` | `label`, `value`, `sub`, `total`, `translate` | One label and amount row inside an `<mj-table css-class="summary">` |
+
+Override a partial the same way as a template, by creating the file at its path in your app. Every email that uses it changes.
+
+## Filters
+
+Besides [Liquid's standard filters](https://shopify.github.io/liquid/filters/abs/), templates have these. The names follow common Liquid conventions where they mean the same thing.
+
+| Filter | Example | Result |
+| --- | --- | --- |
+| `money` | `{{ '10.5' \| money }}` | `$10.50`, in the email's currency |
+| `money_with_currency` | `{{ '10.5' \| money_with_currency }}` | `$10.50 USD` |
+| `date` | `{{ order.completed_at \| date: 'long' }}` | A date in the store's time zone. Takes a named format (`short`, `long`, `default`) or a `strftime` pattern such as `'%Y-%m-%d'` |
+| `t` | `{{ 'order_mailer.confirm_email.dear_customer' \| t: name: order.customer_name }}` | A Spree translation, with its placeholders filled in |
+| `raw` | `{{ product.description_html \| raw }}` | Prints the value without escaping. See below |
+
+Most amounts already arrive formatted, as `display_total`, `display_amount` and the like, so `money` is only needed for a raw amount.
+
+## Escaping
+
+Everything a template prints is HTML-escaped. A customer who types `<a href="https://evil.test">Click to verify</a>` as their name sees that text in the email, not a live link — and so does the store owner reading the new-order notification.
+
+`raw` turns escaping off for one value. Only use it for HTML that was cleaned when it was saved, such as a product's rich-text description. Never use it on a name, an address or a note.
+
+## The plain-text version
+
+Spree builds each email's plain-text version from its HTML, writing links as `label (url)`, so the two can never drift apart. To write the text by hand instead, add a `.text.liquid` file next to the template:
+
+```liquid server/app/views/spree/order_mailer/confirm_email.text.liquid
+Thanks for your order {{ order.number }}, {{ order.customer_name }}.
+
+Total: {{ order.display_total }}
+```
+
+Nothing is escaped in the text version.
+
+## Mistakes surface in development
+
+In development and test, a variable that does not exist raises an error instead of printing nothing, so `{{ order.nubmer }}` fails your spec rather than sending a blank. In production it prints nothing. A template that loops endlessly fails that one email instead of stalling your background jobs.
+
+To look at every email with real data, open the mailer previews at `/rails/mailers` on your Spree server.
+
+## Your own mailers
+
+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.
+
+To give a new email the same data contract as Spree's own, render it from a Liquid template instead:
+
+```ruby server/app/mailers/spree/welcome_mailer.rb
+module Spree
+ class WelcomeMailer < BaseMailer
+ def welcome_email(customer, store)
+ @current_store = store
+
+ with_store_locale(store) do
+ mail_template({ customer: email_data(customer, Spree.api.customer_serializer) }, to: customer.email)
+ end
+ end
+ end
+end
+```
+
+The template goes at `server/app/views/spree/welcome_mailer/welcome_email.liquid`. `email_data` serializes a record the way templates read it; pass a URL that carries a token as its own variable rather than serializing it.
+
+## Related
+
+- [Email Template Variables](/developer/customization/email-variables) — every customer email and the data it receives
+- [Upgrading from 5.6 to 6.0](/developer/upgrades/5.6-to-6.0#emails-render-from-liquid-templates) — moving ERB email overrides to Liquid
+- [Sending out Emails](/developer/deployment/emails) — which emails Spree sends, and handing customer emails to your storefront
+- [Emails provider setup](/developer/providers/emails) — SMTP configuration
diff --git a/docs/developer/deployment/emails.mdx b/docs/developer/deployment/emails.mdx
index 76348937a4..f16fa44aaf 100644
--- a/docs/developer/deployment/emails.mdx
+++ b/docs/developer/deployment/emails.mdx
@@ -13,7 +13,7 @@ Spree handles two categories of emails:
## Customer-Facing Emails
-By default, **Spree sends all customer transactional emails itself**. This works for every client of the API: mobile apps, custom frontends, POS integrations — no storefront required. Delivery uses the same [SMTP configuration](#configuration) as system emails.
+By default, **Spree sends all customer transactional emails itself**. This works for every client of the API: mobile apps, custom frontends, POS integrations — no storefront required. Delivery uses the same [SMTP configuration](#configuration) as system emails, and every email renders from a Liquid template you can override — see [Email Templates](/developer/customization/emails).
Customer emails can be turned off in the admin under **Settings → Emails** — do this when your storefront takes over sending them (below), otherwise customers receive both.
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index 7fcbe92b21..67e92de092 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -710,6 +710,29 @@ Nothing in 5.6 could reach it: there was no API endpoint and no admin screen, so
If you subclassed `Spree::Report` in your own application, that class no longer has a superclass and will raise on boot. Move the question to one of the two replacements above.
+## Emails render from Liquid templates
+
+Every transactional email now renders from a Liquid template written in MJML instead of an ERB view. Templates read serializer data rather than models, keep their Rails view paths, carry their subject line, and get a plain-text version generated from the HTML. See [Email Templates](/developer/customization/emails) for how they work.
+
+**If your app overrides no emails, there is nothing to do.** The emails look the same.
+
+**If your app overrides Spree's emails with ERB**, those files are no longer used and Spree sends its default design instead, without a warning. Look for them under `app/views/spree/*_mailer/` and `app/views/spree/shared/`, and port each to the `.liquid` file at the same path:
+
+| ERB view (removed) | Liquid template |
+| --- | --- |
+| `spree/shared/_base_mailer_header`, `_base_mailer_footer`, `_base_mailer_stylesheets`, `_mailer_logo`, `_purchased_items_styles` | `layouts/spree/base_mailer.liquid` |
+| `spree/shared/_order_summary_section`, `_purchased_items_table`, `purchased_items_table/*` | `spree/shared/_order_summary.liquid`, `_line_item.liquid`, `_purchase_totals.liquid`, `_summary_row.liquid` |
+| `spree/shared/_fulfillment_group_section`, `_purchase_totals` | `spree/shared/_fulfillment_group.liquid`, `_purchase_totals.liquid` |
+| `spree/<mailer>/<email>.html.erb` and `.text.erb`, for every mailer | `spree/<mailer>/<email>.liquid`, plus an optional `<email>.text.liquid` |
+
+Other changes that come with it:
+
+- **Subjects moved into the templates.** Each template's front matter holds its subject. `Spree::BaseMailer#order_email_subject` is removed.
+- **The mailer view helpers are removed.** `Spree::MailHelper` (`name_for`), `Spree::BaseHelper` (`spree_storefront_resource_url`), `Spree::FulfillmentHelper` and `Spree::DigitalAssetHelper` are gone. Templates get the same values as serializer fields, such as `order.customer_name` and `item.url`.
+- **Every email has a plain-text part**, generated from the HTML. Seven emails that had none now have one.
+- **Alba moved into `spree_core`**, with its configuration, so core's staff emails render in installations without `spree_api`.
+- **Your own mailers keep working.** A mailer that inherits `Spree::BaseMailer` and calls `mail` with its own ERB views is wrapped in the new email layout, and the `spree/shared/mailer_hero` and `mailer_button` partials remain for its views. See [Your own mailers](/developer/customization/emails#your-own-mailers).
+
## Deprecated in 6.0, removed in 6.1
Every rename keeps the legacy name working for one release with a deprecation warning. The notable ones:
diff --git a/docs/docs.json b/docs/docs.json
index 3829e04eb9..8f772a977f 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -384,10 +384,6 @@
"source": "/developer/customization/routes",
"destination": "/v5/developer/customization/routes"
},
- {
- "source": "/developer/customization/emails",
- "destination": "/v5/developer/customization/emails"
- },
{
"source": "/developer/core-concepts/adjustments",
"destination": "/developer/core-concepts/fees"
@@ -905,7 +901,9 @@
"developer/customization/model-preferences",
"developer/customization/metadata",
"developer/customization/permissions",
- "developer/customization/decorators"
+ "developer/customization/decorators",
+ "developer/customization/emails",
+ "developer/customization/email-variables"
],
"icon": "code"
},
diff --git a/docs/plans/6.0-email-template-editor.md b/docs/plans/6.0-email-template-editor.md
new file mode 100644
index 0000000000..c5afcbefcb
--- /dev/null
+++ b/docs/plans/6.0-email-template-editor.md
@@ -0,0 +1,152 @@
+# Email Template Editor
+
+**Status:** Design finalized — nothing built
+**Target:** Spree 6.0
+**Depends on:** `6.0-liquid-mjml-emails.md` (Liquid and MJML templates, the template lookup, email serializers), `6.0-admin-rbac.md` (permission catalog), `6.0-admin-spa.md` (dashboard)
+**Author:** Damian Legawiec
+**Last updated:** 2026-09-30
+**Tracking:** Linear V-3729 · GitHub spree/spree#14775
+
+## Summary
+
+Every transactional email Spree sends renders from a Liquid template written in MJML, and today only a developer can change one, by adding a file to the app. This plan lets merchants edit the emails their customers receive in the dashboard: each customer email, and the layout and shared blocks those emails are built from. Staff, store-owner and seller emails stay as Spree ships them. Edits are saved as a draft and go live when published; Spree finds the published version before the file, so an edited email goes out on the next send with no deploy. The editor shows the template's code next to a preview rendered on the server by the same renderer customers' emails go through, lists the variables the email receives, sends a test email, and keeps a history the merchant can revert to. Store branding settings (colors, fonts) style every customer email without touching its code, and survive a revert. When a Spree upgrade changes a default the merchant has customized, the dashboard says so and shows what changed.
+
+## Key Decisions (do not deviate without discussion)
+
+- **Preview renders on the server** (2026-09-30). The dashboard sends the draft template to an Admin API endpoint; the Ruby renderer fills it with sample data and returns the HTML and text parts. What the merchant sees is exactly what customers receive, there is one renderer and one set of filters to maintain, and sending a test email is the same call with a recipient. Rendering in the browser stays an option for later if typing responsiveness demands it.
+- **The database is one more step in the existing lookup, in front of the files.** A store's saved template for a key wins; without one, the app's file, then Spree's own file, answer as today. No mailer changes: the key (`spree/order_mailer/confirm_email`) is the same name the file lookup uses. A developer's file override and a merchant's saved template can coexist; the merchant's wins for their store.
+- **Templates are store-scoped records** (`belongs_to :store` through `Spree::SingleStoreResource`), following the rule for store-owned data. A template never leaks between stores.
+- **Only customer emails are editable** (2026-09-30). Merchants edit what their customers receive: order confirmation, cancellation and payment link, the multi-seller purchase confirmation, shipping, refund, downloads, customer password reset and data export, newsletter confirmation and company invitation. Staff emails in core (admin and seller password resets, staff invitations, import and export results, disabled webhooks), the store-owner notifications and the seller emails stay as Spree's files. The line is who reads the email, not which gem ships it.
+ - **Accepted trade-off:** a merchant cannot reword the new-order notification their own staff receives, or the emails sent to sellers, from the dashboard; a developer still can, with a file.
+- **Customer emails can use an edited layout and edited shared partials** (2026-09-30). A merchant can edit `layouts/spree/base_mailer` and the `spree/shared/*` partials, so the footer or the item row changes once for every customer email.
+ - **Accepted trade-off:** one bad edit to the layout or a partial affects every customer email. Publishing a layout or partial therefore validates every customer email of the store, not just one.
+- **Emails that are not editable never read store templates** (2026-09-30). Staff, store-owner and seller emails render with Spree's own layout and partials (or the app's files), even when the store has published edited versions. A template edit can never break or rebrand a password reset for staff.
+ - **Accepted trade-off:** the lookup must know which emails are editable, and a merchant's footer change does not appear on staff emails.
+- **Edits are drafts until published** (2026-09-30). Saving stores a draft; a separate Publish step makes it live and records a revision. Teams can stage and review a change before customers see it.
+ - **Accepted trade-off:** a draft state per template, a publish endpoint and UI, and every screen must make clear whether it shows the draft or the published version.
+- **A published template must render.** Publishing validates by rendering with sample data under strict variables: a Liquid syntax error, an unknown variable, an unknown filter or invalid MJML is refused with the line and message, so a merchant can never break an email that is already being sent. Drafts may be saved in any state, since they are work in progress. Production sends stay lenient (an unknown variable prints nothing), as today.
+- **One template serves every language, with optional per-language versions** (2026-09-30). A saved template applies to every language, using translation keys (`{{ 'key' | t }}`) or plain text; a merchant can add a version for one language when its copy must differ. The lookup tries the email's language first, then the every-language version, then the files.
+ - **`locale` is never NULL:** the every-language version stores `locale = 'any'`, because a unique index treats NULLs as distinct and would let two every-language rows exist for one key.
+- **History is the live row plus an append-only revisions table** (2026-09-30). `spree_email_templates` holds what is published, so the lookup on every send is one indexed read; `spree_email_template_revisions` records each publish. Rejected: one versions table with a current flag, which makes every send query the latest version and needs the flag kept consistent under concurrent publishes.
+- **Preview uses the latest matching record, and the merchant can pick another** (2026-09-30). Each email builds its sample from the store's most recent matching record (last completed order, fulfillment, return), falls back to an in-memory sample for a new store, and accepts a record id so a merchant can check a specific case (a discount, a multi-parcel order).
+- **Test emails go only to the signed-in admin** (2026-09-30). The endpoint cannot be used to send store-branded mail, a phishing risk, to arbitrary addresses. To check another inbox, the admin forwards it.
+- **The editor is CodeMirror 6** (2026-09-30), as a headless `CodeEditor` component in `@spree/dashboard-ui` so the seller panel and plugins can reuse it. It is modular and small, and custom completions for Liquid variables and MJML tags are straightforward. Liquid highlighting inside HTML needs a small custom mode. Rejected: Monaco (a multi-megabyte bundle with web workers, poor on mobile) and a plain textarea (no highlighting or autocomplete).
+- **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.
+- **The Admin API serves each editable email's variables**, for the editor's autocomplete. How they are derived (declared per email, or read from a sample run of the mailer) is settled during implementation; `email-variables.mdx` is maintained by hand until then.
+
+## Design Details
+
+### Data model
+
+```
+spree_email_templates spree_email_template_drafts spree_email_template_revisions
+───────────────────── ─────────────────────────── ──────────────────────────────
+id id id
+store_id → spree_stores store_id → spree_stores email_template_id → spree_email_templates
+key string, not null key string, not null subject text
+locale string, not null locale string, not null body text, not null
+subject text subject text base_digest string, not null
+body text, not null body text, not null published_by (acted_by)
+base_digest string, not null base_digest string, not null created_at
+published_at datetime, not null updated_by (acted_by) index (email_template_id, created_at)
+created_at, updated_at created_at, updated_at
+unique (store_id, key, locale) unique (store_id, key, locale)
+```
+
+- **`key`** is the name the lookup uses: an editable email's view path (`spree/order_mailer/confirm_email`), the layout (`layouts/spree/base_mailer`) or a partial's render name (`spree/shared/line_item`). It is validated against the editable set and what Spree and the app ship, so a store cannot create a template nothing renders or a staff email it may not edit.
+- **`locale`** is a language code, or `'any'` for the version every language uses.
+- **`subject`** is set for emails and empty for the layout and partials.
+- **`base_digest`** is the SHA-256 of the default file's source when the merchant started from it. Comparing it with the current default's digest is how the dashboard knows an upgrade changed the default underneath the merchant's version.
+- **Drafts** hold work in progress, one per store, key and language. Publishing validates the draft, copies it into `spree_email_templates` (creating the row on first publish), appends a revision and deletes the draft.
+- **Reverting to a revision** copies it into the draft; the merchant publishes it like any other change. **Reverting to the default** deletes the store's published template and draft, so the file answers again. History is never rewritten.
+- The published model publishes lifecycle events (`email_template.published`, `.deleted`), so integrations and audit tooling see what customers will now receive.
+
+### Lookup
+
+An editable-email registry names the customer emails, `Spree::Emails.editable_templates` in `spree_emails`, which an extension appends to for its own customer emails. When a mailer renders one of them, `Spree::Emails::TemplateResolver#find(key)` gains a store:
+
+1. the store's published template for the key in the email's language
+2. the store's published template for the key with `locale = 'any'`
+3. the app's `app/views/<key>.liquid`
+4. the first gem's `app/views/<key>.liquid`
+
+Partials and the layout resolve the same way through the renderer's file system, so a published `layouts/spree/base_mailer` or `spree/shared/line_item` applies to every customer email that uses it. For any other email the resolver is built without the store, so steps 1 and 2 never run and the layout and partials come from files. A preview renders the draft being edited in place of its published version, and the published versions of everything else.
+
+### Branding
+
+Store preferences, all optional, defaulting to today's design:
+
+- `preferred_email_accent_color` (buttons, links)
+- `preferred_email_background_color`, `preferred_email_card_color`
+- `preferred_email_text_color`, `preferred_email_heading_color`
+- `preferred_email_font` (from a fixed list of email-safe and web fonts, each with its fallback stack)
+
+`Spree::Emails::StoreSerializer` exposes them as `store.branding`. The default layout reads them in `<mj-attributes>` and `<mj-style>`, so every default email follows them. A merchant's edited layout can read them too, or ignore them.
+
+### Admin API
+
+Under `/api/v3/admin/email_templates`, keyed by the template key (URL-encoded), scoped to the current store:
+
+| Endpoint | What it does |
+| --- | --- |
+| `GET /email_templates` | Every editable template: key, name, kind (email, layout, partial), languages customized, whether a draft exists, whether the default changed since |
+| `GET /email_templates/:key?locale=` | The published version (the store's, else the default), the draft if any, the default, and the variables it receives |
+| `PUT /email_templates/:key/draft` | Save the draft's subject and body, in any state |
+| `DELETE /email_templates/:key/draft` | Discard the draft |
+| `POST /email_templates/:key/publication` | Publish the draft; renders it (and, for the layout or a partial, every customer email) with sample data; 422 with line-level errors when anything does not render |
+| `DELETE /email_templates/:key?locale=` | Revert to the default |
+| `POST /email_templates/:key/preview` | Render an unsaved subject and body with sample data (`record_id` optional); returns subject, HTML and text |
+| `POST /email_templates/:key/test_email` | Send the draft or the published version to the signed-in admin |
+| `GET /email_templates/:key/revisions` | History, newest first |
+| `POST /email_templates/:key/revisions/:id/restoration` | Copy a revision into the draft |
+| `GET /email_templates/:key/default_diff` | The default as it was when customized, and as it is now |
+
+Publish, preview, test send and restore are not CRUD on the template itself, so each is its own nested resource with `create`, per the API conventions.
+
+### Sample data
+
+Each email declares how to build its sample: the store's most recent matching record (the last completed order, fulfillment, return), a record the merchant picks by its id, or an unsaved sample built in memory so a brand-new store can still preview. Every lookup is scoped to the current store. The same samples feed validation on publish. Token-carrying values (reset links, invitation links) get placeholder URLs, never a real token.
+
+### Dashboard
+
+A new **Settings → Emails → Templates** area (next to the existing sender settings):
+
+- A list of the customer emails, the layout and the shared blocks, showing which are customized and which have an updated default.
+- The editor: language switcher, subject field, CodeMirror editor with MJML and Liquid highlighting and variable autocomplete, preview pane (desktop and mobile widths, HTML and plain-text tabs, a record picker) refreshed on pause, "Send test email", "Save draft", "Publish", "Discard draft", "Revert to default", and a history drawer. The screen always says whether it shows the draft or the published version.
+- An "Updated by Spree" banner with a side-by-side diff of the old and new default, and the option to keep the customized version or start again from the new default.
+- A **Branding** card for the colors and fonts, with the preview reflecting them.
+
+All copy goes through i18next in every locale file, per the dashboard rules.
+
+## Migration Path
+
+1. **Models and lookup**: `Spree::EmailTemplate`, `Spree::EmailTemplateDraft`, `Spree::EmailTemplateRevision`, one migration, the store and language steps in `TemplateResolver`, publish workflow with validation, lifecycle events, permission catalog entry `email_templates`.
+2. **Sample data and preview**: per-email sample builders, the preview and test email endpoints.
+3. **Admin API**: the remaining endpoints, serializers, integration specs, OpenAPI regeneration, Admin SDK methods.
+4. **Branding**: store preferences, `store.branding` in the store serializer, the default layout reading them, the branding card.
+5. **Dashboard editor**: `CodeEditor` in `@spree/dashboard-ui`, the list, editor, preview, drafts and publishing, history, revert, update banner with diff.
+6. **Docs**: merchant guide in `docs/user/settings/emails`, developer notes on how saved templates interact with file overrides, and the Admin API reference.
+
+## Constraints on Current Work
+
+- **Keep every email's data in its serializer and every token in its mailer.** The editor shows the serialized variables and nothing else; a value a mailer computes in Ruby without passing it to the template cannot be offered to merchants.
+- **Don't add Ruby-only template features.** Anything a template needs must be a Liquid filter or a serialized field, so a saved template renders exactly like a file.
+- **Renaming an email key is now a data migration.** Saved templates reference keys; renaming a mailer method needs a rake task moving stored templates to the new key.
+- **Changing a default template triggers the "updated by Spree" banner** for every store that customized it. Change defaults deliberately, and describe the change in release notes.
+- **Keep partial arguments stable.** Merchants can edit partials and the emails that call them independently, so renaming or removing a partial's argument breaks stores that customized either side. Add arguments; don't rename them.
+- **Any new way to send an email must go through the lookup.** A mailer that renders a template itself would skip the store's published version.
+- **A new customer email must be registered as editable** in `Spree::Emails.editable_templates` (with a sample builder), or merchants cannot edit it. A new staff, store-owner or seller email must not be registered.
+
+## Open Questions
+
+None. Rendering previews in the browser, for instant feedback while typing, is deferred until server-side preview proves too slow in practice.
+
+## References
+
+- `6.0-liquid-mjml-emails.md`: the renderer, template keys, email serializers
+- `6.0-admin-rbac.md`: permission catalog, the rule for sensitive resources
+- `6.0-admin-spa.md`: dashboard conventions, settings navigation
+- `6.0-action-actors.md`: `acted_by` for who saved a revision
+- `docs/developer/customization/emails.mdx`, `docs/developer/customization/email-variables.mdx`
diff --git a/docs/plans/6.0-liquid-mjml-emails.md b/docs/plans/6.0-liquid-mjml-emails.md
new file mode 100644
index 0000000000..5745a4c2aa
--- /dev/null
+++ b/docs/plans/6.0-liquid-mjml-emails.md
@@ -0,0 +1,186 @@
+# Liquid and MJML Email Templates
+
+**Status:** In Review — the whole plan is built on `feat/emails-liquid` (spree/spree#14772)
+**Target:** Spree 6.0 (moved from 6.1 on 2026-09-29)
+**Depends on:** v3 serializers (`spree_api`), `spree_emails` (5.6 rebuild)
+**Author:** Damian Legawiec
+**Last updated:** 2026-09-30
+**Tracking:** Linear V-3720 · GitHub spree/spree#14755
+
+## Summary
+
+Transactional emails are the last HTML Spree renders through Rails views. This plan replaces all 61 ActionMailer ERB templates (16 mailers across `spree_core` and `spree_emails`) with **Liquid** templates written in **MJML**. Liquid fills in the data first, then MJML turns the result into email-safe HTML, using the `mrml` gem (a Rust port of MJML) with no Node involved. Templates read plain JSON produced by serializers, never models. This makes the templates:
+
+- **Portable.** Liquid also runs in Node through `liquidjs`.
+- **Safe to hand to merchants.** Liquid is built for untrusted templates.
+- **Much shorter** than the hand-written HTML tables they replace.
+
+Three things are out of scope and come later on this foundation: merchant editing in the dashboard, templates stored in the database, and live previews. Action Mailer still delivers every email.
+
+## Key Decisions (do not deviate without discussion)
+
+- **Liquid for data, MJML for layout** (2026-09-24).
+ - **Why Liquid:** it's the only template language with maintained, first-class engines in both Ruby (`liquid`) and TypeScript (`liquidjs`). That matches the long-term direction of shrinking Rails in the stack. It was also designed for untrusted, merchant-written templates. Handlebars, the other common choice for email templates, has only a weak Ruby port and a history of code-execution vulnerabilities when compiling templates from outside sources.
+ - **Why MJML:** it's the most widely used email layout language. A dozen layout tags (`mj-section`, `mj-column`, `mj-button`) compile to the nested tables, inline styles and Outlook workarounds that email clients need, and mobile stacking comes built in.
+ - **Rejected: React Email, Maizzle (now Vue with Tailwind) and other Tailwind-for-email tools.** They are build-time tools on Node, so the file an author writes is not the file that runs. Merchant editing would need Node on the server, or would expose unreadable compiled output.
+ - **Rejected: React Email's visual editor.** Templates must be managed as code.
+ - **Rejected: plain HTML tables with Liquid.** Nothing new to learn, but Spree would keep maintaining the fragile table markup by hand.
+- **Liquid renders first, then MJML, on every email** (2026-09-24). Loops and conditions can then sit anywhere between MJML tags without `<mj-raw>` wrappers, and partials pulled in by `{% render %}` compile together with the template. Measured with `mrml`, MJML takes about 0.6 milliseconds per email and Liquid about 1.4 milliseconds, so there's nothing to cache.
+- **Every output is escaped unless marked safe** (2026-09-24). Liquid doesn't escape HTML by default. A customer named `<a href="https://evil.test">Click to verify</a>` renders a live link, including into the store owner's new-order notification. Every value a template prints is HTML-escaped, which was verified to neutralize that input. Values known to be safe HTML opt out explicitly with a `raw` filter. Escaping before MJML also stops customer data from forming MJML tags.
+ - **Escaping happens where output is written, not through Liquid's `global_filter`** (2026-09-29, found while building). `{% assign %}` runs through the global filter too, so a value was escaped once when assigned and again when printed, and assigned numbers and lists became strings. Spree instead extends Liquid's variable output, active only inside an email render.
+ - **Partials inherit escaping and strict mode** (2026-09-29, found while building). `{% render %}` gives a partial a fresh context that Liquid does not carry these settings into, so without Spree's context subclass everything a partial printed skipped escaping. A partial may leave an argument out (it reads as empty); a misspelled field still raises.
+- **Templates keep Rails view paths** (2026-09-25). A template sits where its ERB sat, with the extension changed: `app/views/spree/order_mailer/confirm_email.liquid`. That path is also the template's **key**, so a later database row or Node renderer addresses it as `spree/order_mailer/confirm_email`. The upgrade note is a list of renames, and Rails developers already know where to look.
+ - **Accepted trade-off:** template names are tied to Ruby mailer classes and methods for good. A future Node renderer keeps these paths rather than getting cleaner names, and renaming a mailer or one of its methods becomes a breaking change for every app that overrides that email.
+- **Templates read serializer output, never models** (2026-09-25). Liquid "drops" that wrap models aren't used.
+ - **Customer emails** receive hashes from a new family of **email serializers**, each inheriting from the public v3 Store serializer, for example `Spree::Emails::OrderSerializer < Spree::Api::V3::OrderSerializer`. They add only what emails need. The audit found real gaps in the Store serializers: SKU, product link, per-line amount before discounts, the promotion/manual discount split, the order-group purchase breakdown, and fulfillment items as more than ids. Filling those gaps here keeps the public Store API, SDK types and webhook payloads unchanged.
+ - **Accepted trade-off:** a third serializer family to maintain. Email data is a superset of the webhook payload for the same record, not identical to it.
+- **Alba moves into `spree_core`** (2026-09-25). Core's back-office emails (admin and seller password resets, invitations, import and export finished, webhook disabled) must work in every installation, including those without `spree_api`, as the marketplace plan requires. With Alba in core, they use email serializers too, so every email takes its data one way.
+ - **What moves:** `spree_core` gains the `alba` dependency. The Alba setup in `spree/api/config/initializers/alba.rb` (backend, inflector, the `iso8601` type) moves into core, so both gems configure Alba once and identically.
+ - **Where serializers live:** core's email serializers are in `spree/core/app/serializers/spree/emails/` and stand alone, because the v3 Admin serializers live in `spree_api`. That makes each field explicit. The Admin webhook-endpoint serializer, for example, carries `secret_key`, which an email must never render.
+- **Tokens never come from a serializer.** Password-reset, invitation, newsletter, download and payment-link URLs carry secrets. The mailer builds them and passes them as email-specific values. Email serializers never expose a token.
+- **Action Mailer stays the delivery layer.** Mailers keep choosing the recipient, locale, `from` and `reply_to`, keep their guards (for example `CompanyMailer` cancels delivery for a non-pending invitation, and `SellerMailer` cancels when there are no recipients), and keep delivering through the job queue with retries. Only rendering changes.
+- **The template lookup is a chain, with room for a database step.** The renderer asks a resolver for a key. In this plan the resolver checks the host app's Liquid file, then the gem's Liquid default. The later editing work adds a store-scoped database step in front without changing any mailer.
+- **The plain-text part is generated from the HTML** (2026-09-25). Spree converts the final HTML to text, keeping links as `label (url)`. A `confirm_email.text.liquid` next to the template overrides it. This halves the file count, and the text can never drift from the HTML.
+ - **Accepted trade-off:** generated text is a little less tidy than hand-written text. Seven emails that have no text part today gain one.
+- **Copy keeps its translation keys through a `t` filter** (2026-09-25). Default templates read the existing `Spree.t` keys, for example `{{ 'order_mailer.confirm_email.instructions' | t }}`. One template serves every language, and no locale files move. A merchant editing later can still type plain text for a single-language store.
+ - **Accepted trade-off:** default templates read less naturally than plain copy.
+- **No `image_url` filter** (2026-09-29, changed while building). A resized variant is built from the stored file, which a template holding only a URL cannot reach; serializers ship the URL of the size an email shows instead.
+- **Emails with no gap use the Store serializer as it is** (2026-09-29). Customer, seller and company emails read `Spree.api.customer_serializer`, `seller_serializer` and `company_serializer` directly, so a host app's replacement serializer applies to its emails too. Only order, order group, fulfillment and return get email serializers.
+- **Filters are a small, deliberate public interface, with the most widely used Liquid filter names where the meaning matches.** Agents and developers reach for those names first. Matching names where the behavior matches (`money`, `money_with_currency`, `date`, `t`) turns that habit into correct code. Nothing is added just because a Rails helper existed.
+- **The subject lives in the template.** Each template carries its subject line as Liquid, so one email is one self-contained unit. That's the shape a database row takes later.
+- **All 16 mailers migrate in 6.0** (2026-09-25, moved from 6.1 on 2026-09-29). The plan was pulled into 6.0 so the release ships one email stack rather than changing it again one release later, and so merchant editing can start on 6.x without a template migration in between.
+- **ERB overrides of Spree's emails are dropped in 6.0, with no bridge** (2026-09-29, replacing an earlier same-day decision to keep them in a `spree_legacy_emails` gem for one release). 6.0 is a major release that already breaks larger things, the ERB emails were only rebuilt in 5.6, and a bridge would have cost a gem, a CI lane, an ERB step in the lookup and a 6.1 cleanup. An app's ERB override of a Spree email is not rendered, and the default design goes out instead.
+ - **Accepted trade-off (2026-09-30):** there is no warning. A boot-time check listing ignored ERB overrides was built and then removed: it ran on every boot of every app, forever, to catch a one-time upgrade problem the upgrade guide already covers.
+- **Custom mailers keep working unchanged** (2026-09-29). A mailer that inherits `Spree::BaseMailer` and renders its own ERB views with `mail` still gets Spree's layout: core keeps a one-line `layouts/spree/base_mailer.html.erb` that wraps the rendered view in the Liquid layout, so custom emails carry the new header and footer. The `spree/shared/_mailer_hero` and `_mailer_button` ERB partials stay in core, restyled, because custom views commonly use them. Only overrides of Spree's own emails need porting.
+- **The subject is front matter** (2026-09-29). A template opens with a small YAML block holding its subject as Liquid, the Jekyll convention:
+
+ ```liquid
+ ---
+ subject: "{{ store.name }} {{ 'order_mailer.confirm_email.subject' | t }} #{{ order.number }}"
+ ---
+ ```
+
+ The block maps one-to-one onto a subject column when templates move to the database. Rejected: a `{% subject %}` tag in the body, which would have to be dug back out of the body for that move.
+
+## Design Details
+
+### Rendering pipeline
+
+```
+mailer ── key + data ──▶ Spree::Emails::Renderer (spree_core)
+ │
+ ├─ 1. resolve key host .liquid → gem .liquid
+ ├─ 2. Liquid: subject + body escaped output, strict variables, render limits
+ │ body = layout wrapping the template through {{ content_for_layout }}
+ ├─ 3. MJML → HTML mrml
+ └─ 4. text part .text.liquid override, or generated from the HTML
+ ▼
+mail(subject:, html:, text:) ── Action Mailer delivery (unchanged)
+```
+
+- **Dependencies in `spree_core`:**
+ - `liquid`: pure Ruby.
+ - `mrml`: MIT licensed, with precompiled binaries for Linux (glibc and musl, x86_64 and arm64), macOS and Windows, so Docker builds need no Rust toolchain. `mrml` is a single-maintainer binding; if it's abandoned, the fallback is compiling MJML through `mjml` on Node in a separate step, with no change to templates.
+ - `alba`.
+- **The layout** is `app/views/layouts/spree/base_mailer.liquid`: `<mjml>`, `<mj-head>` (fonts and default attributes through `<mj-attributes>`), the header with the store logo, the footer, and `{{ content_for_layout }}` where the body goes. `content_for_layout` is the conventional Liquid name for the same idea. MJML's default Google Fonts import is replaced with the stack the current ERB stylesheet uses.
+- **Partials** are loaded with `{% render 'spree/shared/line_item', item: item %}` and resolve to `app/views/spree/shared/_line_item.liquid`, the Rails partial naming. `render` gives each partial its own isolated variables. The ERB layout tricks that don't exist in Liquid are replaced:
+ - `_mailer_hero` used as a layout with `yield` becomes named MJML styles (`mj-class="heading"`, `greeting`, `lead`, `note`) that templates use directly; `_mailer_button` is plain `<mj-button>`.
+ - `content_for :head` styles move into the layout's `<mj-head>`.
+- **Resource limits.** Liquid's render limits are set so a runaway loop fails one email instead of stalling the job queue. Strict variables make an unknown variable raise in development and test, so a typo like `order.nubmer` fails a spec rather than rendering blank.
+
+### Data each template receives
+
+| Variable | Source |
+| --- | --- |
+| The record (`order`, `order_group`, `fulfillment`, `return`, `customer`, `seller`, `company`, …) | Its email serializer as a hash. Customer emails: `spree_emails` serializers inheriting the v3 Store ones. Back-office emails: core serializers. |
+| `store` | Name, storefront URL, absolute logo URL (mailer logo, falling back to the store logo), support email, address, default currency and locale. One core serializer; no Store API serializer exists for stores today. |
+| Email-specific values | Built by the mailer: reset, invitation, confirmation, download and payment-link URLs with their tokens; the `resend` flag. |
+
+### Template audit (2026-09-25)
+
+What each email's templates read today, and the gaps its serializer has to close. "Store" means the public v3 Store serializer.
+
+| Mailer | Audience | Gaps its email serializer closes |
+| --- | --- | --- |
+| `OrderMailer` (confirm, cancel, store-owner notification, payment link) | customer; store staff | Order: customer name (billing, then shipping, then email fallback, today's `name_for`), `display_total_minus_store_credits`, discounts split into promotion and manual with `label`, delivery totals grouped by rate name. Line item: `sku`, `display_amount` (price × quantity before discounts, not `display_total`), product storefront URL, image URL. |
+| `OrderGroupMailer` (confirm, store-owner notification) | customer; store staff | Almost everything: customer name, PO number, line items, fulfillment groups (seller names, items with quantities and amounts, name, cost), unfulfilled items, every totals field, discounts, fees. The view currently queries the database and multiplies amounts itself; both move into the serializer. |
+| `FulfillmentMailer` (`ShipmentMailer` forwards to it) | customer | The order it belongs to; delivery method name; manifest items with line-item data (today they're ids only); tracking URL. |
+| `ReturnMailer` (refunded) | customer | `display_refunded_total` (Store's `display_refund_total` is a different figure); returned line items with name, SKU and options. |
+| `DigitalAssetMailer` (files ready) | customer | Absolute download URLs (the serializer has relative paths), built by the mailer since they carry tokens. |
+| `CustomerMailer` (password reset, data export) | customer | Nothing; the URLs and expiry come from the mailer. |
+| `NewsletterMailer` (confirmation) | subscriber | Nothing; the confirmation URL comes from the mailer. |
+| `CompanyMailer` (invitation) | buyer | Company name exists; the accept URL comes from the mailer. |
+| `SellerMailer` (approved, suspended, rejected) | seller | Seller name exists; the dashboard URL comes from the mailer. |
+| `AdminUserMailer`, `SellerUserMailer` (password reset) | staff; seller user | Nothing; locale is the store's admin locale, as today. |
+| `InvitationMailer` (invitation, accepted) | invitee; inviter | Resource name, inviter and invitee names (none are serialized today); accept URL from the mailer. |
+| `ExportMailer`, `ImportMailer` (done) | staff | User first name, file name, completed and failed row counts, results URL. |
+| `WebhookMailer` (endpoint disabled) | staff | Name, URL, disabled reason and date. Never `secret_key`. |
+
+Helpers replaced by filters or serializer fields:
+
+- `name_for`, `spree_storefront_resource_url`, `fulfillment_tracking_link_to` and `digital_link_download_url` become serializer fields or mailer-built values.
+- `Spree::Money` and the `display_*` methods become `money` or preformatted `display_*` fields.
+- `I18n.l` and `strftime` become `date`.
+- The image helpers become serializer fields carrying the thumbnail's URL (`item.image_url`, `store.logo_url`).
+- `Spree.t` becomes `t`.
+
+### Filters
+
+| Filter | Example | Notes |
+| --- | --- | --- |
+| `money` / `money_with_currency` | `{{ line_item.amount \| money }}` | Conventional Liquid names; formatted through `Spree::Money` in the email's currency |
+| `date` | `{{ order.completed_at \| date: 'long' }}` | In the store's time zone, never the server's |
+| `t` | `{{ 'order_mailer.confirm_email.dear_customer' \| t: name: order.customer_name }}` | Existing `Spree.t` keys with interpolation |
+| `raw` | `{{ product.description_html \| raw }}` | Opts out of escaping; only for HTML sanitized on write |
+
+### Previews and tests
+
+- The bundled Action Mailer previews (`/rails/mailers`) keep working, because they call the mailers.
+- A shared spec renders every shipped template with factory data under strict variables, so a missing or misspelled variable fails CI.
+- Every rendered email is checked for leftover `{{`, `{%` and `<mj-`, which catches both an unrendered Liquid tag and an MJML tag that didn't compile.
+- An escaping spec renders each customer-facing email with an HTML payload in every free-text field (names, addresses, notes, company names).
+
+### Documentation
+
+- A developer guide in `docs/developer/` on overriding an email: where files go, the layout and partials, filters, escaping, and the plain-text override.
+- **A reference of the variables of every customer email**, maintained by hand in `docs/developer/customization/email-variables.mdx` and published through `llms.txt` too. Agents otherwise guess variable names they have seen on other platforms, and this reference corrects that.
+- A 6.0 upgrade note listing every ERB path with its Liquid replacement.
+
+## Migration Path
+
+1. **Alba into core.** Add the dependency, and move the Alba setup from `spree_api` into core.
+2. **Renderer and resolver in `spree_core`:** `liquid` and `mrml`, the lookup chain, escaping, limits, filters, and text generation.
+3. **Layout and partials** in MJML, matching the current ERB design visually.
+4. **Core mailers** (admin user, seller user, invitation, import, export, webhook), each with its core email serializer and render spec. One mailer per commit.
+5. **`spree_emails` mailers** (order, order group, fulfillment and shipment, return, digital asset, customer, newsletter, company, seller), each with its email serializer and render spec. One mailer per commit.
+6. **Docs:** the override guide, the variable reference for customer emails, and the upgrade note.
+
+## Constraints on Current Work
+
+- **Keep email views dumb.** New emails and changes to existing ones compute values in the mailer, or expose them from a serializer, rather than calling model methods or new helpers from the view. Every model call in a view today is migration work for this plan, and the order-group views that query the database are the worst case.
+- **Don't add new mailer view helpers.**
+- **Don't widen the public Store serializers for an email's sake.** A field only an email needs goes on the email serializer once this plan lands.
+- **Renaming a mailer class or method is a breaking change** once templates are Liquid, because the view path is the template key that apps override (and, later, that database rows reference).
+- **Never put a token in a serializer.** URLs carrying secrets are built by the mailer.
+- **New mailers** (message relay, gift cards) may still ship in ERB before this plan lands, but should follow these rules so their conversion is mechanical.
+
+## Open Questions
+
+None block 6.0. Merchant editing is designed in `6.0-email-template-editor.md`; the items below were its starting brief:
+
+- Editing in the dashboard, database-stored templates as a store-scoped step in front of the resolver, and revision history.
+- Preview renders on the server (decided 2026-09-30): the dashboard sends a draft template to an Admin API endpoint, and the same Ruby renderer fills it with sample data and returns the HTML. What the merchant sees is exactly what customers receive, there is one renderer to maintain, and a send-test-email action is a small addition. Rendering in the browser through `liquidjs` and MJML's browser build stays an option for later, if typing responsiveness demands it; it would mean keeping Spree's filters in step in two languages.
+- Store branding settings (colors, fonts) feeding the layout's `<mj-attributes>`. Today the only branding is the logo and mailer logo.
+- Warning merchants when a default they customized has changed, with a diff.
+
+Each is unblocked by this plan shipping: the resolver chain, the email keys and the data contract are what the editor builds on.
+
+## References
+
+- `6.0-multi-vendor-marketplace.md`: back-office emails stay in core; seller mailers; the order-group confirmation
+- `6.0-digital-assets.md`: `DigitalAssetMailer`
+- `6.0-seller-onboarding-requirements.md`: new `SellerMailer` emails
+- `6.0-email-template-editor.md`: merchant editing in the dashboard, built on this plan
+- `6.1-marketplace-message-relay.md`: `MessageMailer` (new mailer)
+- `6.0-6.1-loyalty-gift-cards-store-credits.md`: gift card mailer (new mailer)
+- Liquid: https://shopify.github.io/liquid/ · `liquidjs`: https://liquidjs.com · MJML: https://mjml.io · `mrml` gem: https://github.com/hardpixel/mrml-ruby
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index 9b9e244218..5bbb4e0ff0 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -1,3 +1,13 @@
+## 2026-09-30: Merchants edit email templates in the dashboard, as drafts published per store
+
+**Context:** Since the Liquid and MJML plan, every email renders from a template only a developer can change. The end goal was always merchant editing; this settles its shape.
+
+**Decision:** Each store can edit its customer emails, and the shared layout and partials those emails use. Staff emails in core, store-owner notifications and seller emails stay as Spree's files and never read a store's edited layout or partials, so a template edit can never break a staff password reset. Edits are saved as drafts and go live when published; publishing renders the template with sample data under strict variables (every customer email, for the layout or a partial) and refuses anything that does not render. Published templates are store-scoped rows found before the files in the template lookup, one version for every language (`locale = 'any'`, never NULL, so the unique index holds) with optional per-language versions. History is an append-only revisions table next to the live row. Preview renders on the server through the same renderer customers' emails use, with the store's latest matching record or one the merchant picks. Test emails go only to the signed-in admin. Branding (colors, fonts) lives in store preferences, independent of template code. Templates are their own permission resource, `email_templates`. The editor is CodeMirror 6 in `@spree/dashboard-ui`.
+
+**Consequences:** A bad layout or partial edit reaches every email, which is why publishing validates them all. Renaming an email key or a partial argument now breaks stores that customized it; keys need a data migration and partial arguments may only be added. Changing a default template shows an "updated by Spree" notice to every store that customized it.
+
+**Plans amended:** `6.0-liquid-mjml-emails.md` (its deferred editing work now points to `6.0-email-template-editor.md`).
+
## 2026-09-30: A return owed nothing completes at zero
**Context:** Once a returned free gift was valued at what the customer paid for it (entry below), its return could never be closed. Reproduced on R1009: a Tee with a free pink Polo, the Polo returned alone, approved and received with a refund total of $0.00. `Returns::Refund` refused any amount that was not positive ("There is nothing left to refund on this return."), and `Returns::Cancel` only accepts requested or approved returns, so the return sat at `received` for good. It kept counting in the dashboard's open-returns counter and the open filter, the customer's return page never showed it finished, and `return.refunded` never reached webhooks. Any return whose refund works out to zero was caught the same way, including one where nothing that arrived was worth anything. Money was never at stake.
@@ -34,6 +44,26 @@ Rejected: refusing codes that do not qualify yet, which would reverse the 2026-0
**Plans amended:** `6.0-core-rewrite-tasks.md` (the "Coupon code wired fully" bullet).
+## 2026-09-29: Liquid and MJML emails move into 6.0, and ERB email overrides are dropped
+
+**Context:** The Liquid and MJML email plan (2026-09-25 entry below) targeted 6.1. Shipping 6.0 with the ERB emails would mean every app customising an email ports it twice in two releases: once to 6.0's rebuilt ERB, once to Liquid. A bridge that kept ERB overrides rendering through 6.0 was built first, as a `spree_legacy_emails` gem, and then removed the same day.
+
+**Decision:** The plan targets 6.0 and is renamed `6.0-liquid-mjml-emails.md`. All 16 mailers convert in 6.0, core's back-office emails included. ERB overrides of Spree's own emails are dropped with no bridge: 6.0 is a major release, the ERB emails were only rebuilt in 5.6, and the bridge cost a gem, a CI lane, an ERB step in the template lookup and a 6.1 cleanup. Custom mailers that render their own ERB views keep working: core keeps a one-line ERB layout that wraps them in the Liquid layout, plus the `mailer_hero` and `mailer_button` partials. A template carries its subject as YAML front matter, which maps straight onto a subject column when templates move to the database.
+
+**Consequences:** An app that overrode one of Spree's emails in ERB must port it to Liquid; until it does, the default design goes out, with no warning beyond the upgrade guide. The mailer view helpers (`name_for`, `spree_storefront_resource_url` and the fulfillment and digital asset helpers) are removed.
+
+**Plans amended:** `6.0-liquid-mjml-emails.md` (renamed from `6.1-liquid-mjml-emails.md`; target, override and subject decisions).
+
+## 2026-09-25: Emails render through Liquid and MJML, reading serializers, not views
+
+**Context:** Transactional emails are the last HTML Spree renders through Rails views: 61 ERB templates across 16 mailers, which call model methods, helpers and even database queries from the view. The longer-term direction is to shrink Rails in the stack, and to let merchants edit email templates from the dashboard later. ERB can do neither safely: it runs arbitrary Ruby and exists only in Ruby.
+
+**Decision:** Every email template becomes Liquid written in MJML. Liquid fills in the data, then MJML (the `mrml` gem, no Node) compiles it to email-safe HTML, on every email. Liquid was picked over Handlebars because it's the only template language with first-class engines in both Ruby and TypeScript, and it was built for untrusted templates. Templates read hashes from email serializers: `spree_emails` serializers inherit the v3 Store serializers for customer emails, and core serializers serve back-office emails. `alba` moves into `spree_core` for that, together with its setup. Output is HTML-escaped by default, tokens are built by mailers and never serialized, templates keep their Rails view paths (which become their keys), the text part is generated from the HTML, and copy keeps its `Spree.t` keys through a `t` filter. Rejected: React Email, Maizzle and other build-time tools (the file you write isn't the file that runs, so merchant editing needs Node); plain HTML tables (fragile markup maintained by hand); widening the public Store serializers for email-only fields.
+
+**Consequences:** Renaming a mailer or one of its methods becomes a breaking change, because the view path is what apps override. Email views must stop calling models and helpers now, so the conversion stays mechanical. Merchant editing, database-stored templates and previews are a later plan built on the resolver chain this one ships.
+
+**Plans amended:** none. `6.0-liquid-mjml-emails.md` is the new plan.
+
## 2026-09-25: Replacement units are flagged, so an order edit counts only what was bought
**Context:** Raising the quantity of an exchanged line on a placed order deleted the line's original fulfillment and its delivery charge (V-3707). Reproduced on `main`: order R1001, one Stainless kettle at $79.99 plus $5.00 Standard delivery, exchanged for Matte Black; raising the line to 2 answered 200, deleted the $5.00 fulfillment with its Stainless unit, took `delivery_total` from 5.0 to 0.0, and released the Stainless allocation instead of adding one. There were two causes. `Exchanges::Fulfill` and `Claims::Resolve` built their replacement units through `order.fulfillment_items.new`; the stock coordinator packs a copy of each, and the order's next save persisted the original as well, so every replacement left a second unit on the line with no fulfillment. `Spree::OrderInventory#verify` then counted every unit on the line against its quantity, found three units for a quantity of two, and removed the one it could reach, the original. With the stray unit gone the edit still added nothing, because the replacement counted as a unit the line already held. The 6.0 returns rebuild had removed `exchanged_unit?` and `original_return_item`, so nothing told a replacement apart from a unit the customer bought.
diff --git a/spree/api/lib/spree/api.rb b/spree/api/lib/spree/api.rb
index 6957f4e9d0..831f9c0413 100644
--- a/spree/api/lib/spree/api.rb
+++ b/spree/api/lib/spree/api.rb
@@ -1,7 +1,5 @@
require 'spree/core'
require 'pagy'
-require 'alba'
-require 'oj'
require 'typelizer'
require 'typelizer/proc_resource_resolution'
require 'typelizer/open_enums'
diff --git a/spree/api/spree_api.gemspec b/spree/api/spree_api.gemspec
index 0c89d81f50..de3348171d 100644
--- a/spree/api/spree_api.gemspec
+++ b/spree/api/spree_api.gemspec
@@ -24,8 +24,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rswag-specs'
- s.add_dependency 'alba', '~> 3.0'
- s.add_dependency 'oj', '~> 3.16'
s.add_dependency 'typelizer', '~> 0.11.0'
s.add_dependency 'spree_core', s.version
diff --git a/spree/core/app/mailers/spree/admin_user_mailer.rb b/spree/core/app/mailers/spree/admin_user_mailer.rb
index c4fbea6653..09c3db2585 100644
--- a/spree/core/app/mailers/spree/admin_user_mailer.rb
+++ b/spree/core/app/mailers/spree/admin_user_mailer.rb
@@ -9,10 +9,9 @@ module Spree
@reset_url = password_reset_url(token, store, redirect_url)
with_store_locale(store, preferred_locale(admin_user, store)) do
- mail(
- to: admin_user.email,
- subject: "#{store.name} #{Spree.t('admin_user_mailer.password_reset_email.subject')}",
- store_url: store.formatted_url
+ mail_template(
+ { user: email_data(admin_user, Spree::Emails::UserSerializer), reset_url: @reset_url },
+ to: admin_user.email, store_url: store.formatted_url
)
end
end
diff --git a/spree/core/app/mailers/spree/base_mailer.rb b/spree/core/app/mailers/spree/base_mailer.rb
index d36027d4d4..928ff5d7f6 100644
--- a/spree/core/app/mailers/spree/base_mailer.rb
+++ b/spree/core/app/mailers/spree/base_mailer.rb
@@ -41,7 +41,7 @@ module Spree
end
def reply_to_address
- current_store.customer_support_email.presence || current_store.mail_from_address
+ current_store.support_email_address
end
def money(amount, currency = nil)
@@ -50,25 +50,70 @@ module Spree
end
helper_method :money
+ # Wraps HTML a mailer rendered from its own ERB views in the Liquid email
+ # layout, so every email a Spree mailer sends carries the store's logo,
+ # header and footer. Called by `layouts/spree/base_mailer.html.erb`.
+ #
+ # @param html [String] the rendered view
+ # @return [ActiveSupport::SafeBuffer]
+ def render_in_email_layout(html)
+ email_renderer.wrap(html, subject: message.subject).html_safe
+ end
+ helper_method :render_in_email_layout
+
def mail(headers = {}, &block)
ensure_default_action_mailer_url_host(headers[:store_url])
+ # Mailers that don't wrap their action in `with_store_locale` still get
+ # the store's default locale, as `mail` applied before Spree 5.6.
+ in_store_locale { super }
+ end
- if @_store_locale_active
- super
- else
- # Subclasses that call `mail` without wrapping their action in
- # `with_store_locale` (e.g. extension mailers) still get the
- # store default locale, as `mail` applied before Spree 5.6.
- with_store_locale(current_store) { super }
+ protected
+
+ # Renders the current action's email from its Liquid template and builds
+ # the message. The template's front matter supplies the subject, and the
+ # plain-text part is generated from the HTML unless a `.text.liquid` sits
+ # next to the template.
+ #
+ # @param assigns [Hash] the template's variables — serializer output and
+ # mailer-built values such as token-carrying URLs, never models
+ # @param template [String] the template key, defaults to the action's view path
+ # @param headers [Hash] mail headers (`to:`, `store_url:`, ...)
+ # @return [Mail::Message]
+ def mail_template(assigns = {}, template: "#{mailer_name}/#{action_name}", **headers)
+ in_store_locale do
+ email_template = email_resolver.find(template) || raise(ArgumentError, "Missing email template #{template}.liquid")
+ email = email_renderer.render(email_template, assigns)
+
+ mail(headers.merge(subject: email.subject)) do |format|
+ format.text { render plain: email.text, layout: false }
+ format.html { render html: email.html.html_safe, layout: false }
+ end
end
end
- protected
+ # The currency an email's amounts are in: its order's, else the store's.
+ #
+ # @return [String]
+ def email_currency
+ (@order || @order_group)&.currency || current_store.default_currency
+ end
- # The "<store> <subject> #<number>" subject line shared by customer-facing
- # order emails, with the optional [RESEND] prefix.
- def order_email_subject(store, subject, number, resend: false)
- "#{resend ? "[#{Spree.t(:resend).upcase}] " : ''}#{store.name} #{subject} ##{number}"
+ # A record as its template reads it: the serializer's JSON, the same data
+ # a renderer outside Ruby would receive. Download links and other bearer
+ # tokens stay out; the mailer builds any URL that carries one.
+ #
+ # @param object [Object, nil] the record
+ # @param serializer [Class] an email serializer
+ # @param params [Hash] serializer params, over the email's store, currency and locale
+ # @return [Hash, nil]
+ def email_data(object, serializer, **params)
+ return if object.nil?
+
+ params = { store: current_store, currency: email_currency, locale: I18n.locale.to_s,
+ storefront_url: current_store.storefront_url.to_s.chomp('/'),
+ hide_credentials: true }.merge(params)
+ JSON.parse(serializer.new(object, params: params).serialize)
end
# URI-based merge preserves existing query params and fragments so the token
@@ -86,6 +131,18 @@ module Spree
private
+ def email_resolver
+ @email_resolver ||= Spree::Emails::TemplateResolver.new(self.class.view_paths.paths.map(&:path))
+ end
+
+ def email_renderer
+ Spree::Emails::Renderer.new(resolver: email_resolver, store: current_store, currency: email_currency)
+ end
+
+ def in_store_locale(&block)
+ @_store_locale_active ? yield : with_store_locale(current_store, &block)
+ end
+
# this ensures that ActionMailer::Base.default_url_options[:host] is always set
# this is only a fail-safe solution if developer didn't set this in environment files
# http://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-in-action-mailer-views
diff --git a/spree/core/app/mailers/spree/export_mailer.rb b/spree/core/app/mailers/spree/export_mailer.rb
index 1fe9f3ea82..f554082e11 100644
--- a/spree/core/app/mailers/spree/export_mailer.rb
+++ b/spree/core/app/mailers/spree/export_mailer.rb
@@ -4,10 +4,9 @@ module Spree
@export = export
with_store_locale(@export.store) do
- mail(
- to: @export.user.email,
- subject: Spree.t('export_mailer.export_done.subject', export_number: @export.number).to_s,
- store_url: current_store.url
+ mail_template(
+ { export: email_data(@export, Spree::Emails::ExportSerializer) },
+ to: @export.user.email, store_url: current_store.url
)
end
end
diff --git a/spree/core/app/mailers/spree/import_mailer.rb b/spree/core/app/mailers/spree/import_mailer.rb
index eaed81d836..87c3a9d464 100644
--- a/spree/core/app/mailers/spree/import_mailer.rb
+++ b/spree/core/app/mailers/spree/import_mailer.rb
@@ -4,10 +4,9 @@ module Spree
@import = import
with_store_locale(@import.store) do
- mail(
- to: @import.user.email,
- subject: Spree.t('import_mailer.import_done.subject', import_number: @import.number).to_s,
- store_url: current_store.url
+ mail_template(
+ { import: email_data(@import, Spree::Emails::ImportSerializer) },
+ to: @import.user.email, store_url: current_store.url
)
end
end
diff --git a/spree/core/app/mailers/spree/invitation_mailer.rb b/spree/core/app/mailers/spree/invitation_mailer.rb
index 3df4948252..bd5f40245d 100644
--- a/spree/core/app/mailers/spree/invitation_mailer.rb
+++ b/spree/core/app/mailers/spree/invitation_mailer.rb
@@ -8,9 +8,10 @@ module Spree
# default store's branding on multi-store installs.
@current_store = invitation.store
with_store_locale(invitation.store) do
- mail(to: invitation.email,
- subject: Spree.t('invitation_mailer.invitation_email.subject',
- resource_name: invitation.resource&.name))
+ mail_template(
+ { invitation: email_data(invitation, Spree::Emails::InvitationSerializer), accept_url: accept_url(invitation) },
+ to: invitation.email
+ )
end
end
@@ -19,10 +20,26 @@ module Spree
@invitation = invitation
@current_store = invitation.store
with_store_locale(invitation.store) do
- mail(to: invitation.inviter.email,
- subject: Spree.t('invitation_mailer.invitation_accepted.subject',
- invitee_name: invitation.invitee&.name,
- resource_name: invitation.resource&.name))
+ mail_template(
+ { invitation: email_data(invitation, Spree::Emails::InvitationSerializer) },
+ to: invitation.inviter.email
+ )
+ end
+ end
+
+ private
+
+ # The legacy `spree_admin` gem's own acceptance page when it is installed,
+ # otherwise the dashboard's.
+ def accept_url(invitation)
+ spree_routes = Spree::Core::Engine.routes.url_helpers
+
+ if spree_routes.respond_to?(:admin_invitation_url)
+ spree_routes.admin_invitation_url(invitation, token: invitation.token, host: invitation.store.formatted_url)
+ else
+ # Built with the mailer's own URL options, as the view built it before.
+ ensure_default_action_mailer_url_host
+ main_app.admin_invitation_acceptance_url(invitation)
end
end
end
diff --git a/spree/core/app/mailers/spree/seller_user_mailer.rb b/spree/core/app/mailers/spree/seller_user_mailer.rb
index f4efbf931d..de9ad22731 100644
--- a/spree/core/app/mailers/spree/seller_user_mailer.rb
+++ b/spree/core/app/mailers/spree/seller_user_mailer.rb
@@ -13,10 +13,9 @@ module Spree
@reset_url = password_reset_url(token, store, redirect_url)
with_store_locale(store, preferred_locale(seller_user, store)) do
- mail(
- to: seller_user.email,
- subject: "#{store.name} #{Spree.t('seller_user_mailer.password_reset_email.subject')}",
- store_url: store.formatted_url
+ mail_template(
+ { user: email_data(seller_user, Spree::Emails::UserSerializer), reset_url: @reset_url },
+ to: seller_user.email, store_url: store.formatted_url
)
end
end
diff --git a/spree/core/app/mailers/spree/webhook_mailer.rb b/spree/core/app/mailers/spree/webhook_mailer.rb
index 1920074347..56ccbba451 100644
--- a/spree/core/app/mailers/spree/webhook_mailer.rb
+++ b/spree/core/app/mailers/spree/webhook_mailer.rb
@@ -7,9 +7,9 @@ module Spree
@current_store = webhook_endpoint.store
with_store_locale(webhook_endpoint.store) do
- mail(
+ mail_template(
+ { endpoint: email_data(@endpoint, Spree::Emails::WebhookEndpointSerializer) },
to: @current_store.new_order_notifications_email.presence || @current_store.mail_from_address,
- subject: Spree.t('webhook_mailer.endpoint_disabled.subject', endpoint_name: @endpoint.name || @endpoint.url),
store_url: @current_store.formatted_url
)
end
diff --git a/spree/core/app/models/spree/store.rb b/spree/core/app/models/spree/store.rb
index e95a8aa591..d6de57418c 100644
--- a/spree/core/app/models/spree/store.rb
+++ b/spree/core/app/models/spree/store.rb
@@ -543,6 +543,21 @@ module Spree
allowed_origins.any? { |allowed_origin| allowed_origin.matches?(url) }
end
+ # The logo emails show: the dedicated mailer logo, else the store logo.
+ #
+ # @return [ActiveStorage::Attached::One, nil] nil when neither is an image
+ def email_logo
+ logo = mailer_logo.attached? ? mailer_logo : self.logo
+ logo if logo.attached? && logo.variable?
+ end
+
+ # The address customers are told to write to: the support address, else the sender address.
+ #
+ # @return [String, nil]
+ def support_email_address
+ customer_support_email.presence || mail_from_address
+ end
+
# Returns the states available for checkout for the store
# @param country [Spree::Country] the country to get the states for
# @return [Array<Spree::State>]
diff --git a/spree/core/app/serializers/spree/emails/base_serializer.rb b/spree/core/app/serializers/spree/emails/base_serializer.rb
new file mode 100644
index 0000000000..f4502e5045
--- /dev/null
+++ b/spree/core/app/serializers/spree/emails/base_serializer.rb
@@ -0,0 +1,14 @@
+module Spree
+ module Emails
+ # Base for the serializers that feed email templates. Emails read plain
+ # JSON, the same data a renderer outside Ruby would receive, never models.
+ # Never expose a token here: URLs carrying secrets are built by the mailer.
+ class BaseSerializer
+ include Alba::Resource
+
+ attribute :id do |object|
+ object.prefixed_id if object.respond_to?(:prefixed_id)
+ end
+ end
+ end
+end
diff --git a/spree/core/app/serializers/spree/emails/export_serializer.rb b/spree/core/app/serializers/spree/emails/export_serializer.rb
new file mode 100644
index 0000000000..31937d8fb4
--- /dev/null
+++ b/spree/core/app/serializers/spree/emails/export_serializer.rb
@@ -0,0 +1,13 @@
+module Spree
+ module Emails
+ class ExportSerializer < BaseSerializer
+ attributes :number, :results_url
+
+ attribute :filename do |export|
+ export.attachment.filename.to_s if export.attachment.attached?
+ end
+
+ one :user, resource: Spree::Emails::UserSerializer
+ end
+ end
+end
diff --git a/spree/core/app/serializers/spree/emails/import_serializer.rb b/spree/core/app/serializers/spree/emails/import_serializer.rb
new file mode 100644
index 0000000000..0c835be43f
--- /dev/null
+++ b/spree/core/app/serializers/spree/emails/import_serializer.rb
@@ -0,0 +1,19 @@
+module Spree
+ module Emails
+ class ImportSerializer < BaseSerializer
+ attributes :number
+
+ attribute :results_url, &:results_page_url
+
+ attribute :completed_count do |import|
+ import.rows_status_counts['completed'].to_i
+ end
+
+ attribute :failed_count do |import|
+ import.rows_status_counts['failed'].to_i
+ end
+
+ one :user, resource: Spree::Emails::UserSerializer
+ end
+ end
+end
diff --git a/spree/core/app/serializers/spree/emails/invitation_serializer.rb b/spree/core/app/serializers/spree/emails/invitation_serializer.rb
new file mode 100644
index 0000000000..bccb624131
--- /dev/null
+++ b/spree/core/app/serializers/spree/emails/invitation_serializer.rb
@@ -0,0 +1,28 @@
+module Spree
+ module Emails
+ class InvitationSerializer < BaseSerializer
+ attributes :email
+
+ attribute :resource_name do |invitation|
+ invitation.resource.try(:name)
+ end
+
+ attribute :inviter_name do |invitation|
+ invitation.inviter.try(:full_name).presence || invitation.inviter.try(:name)
+ end
+
+ attribute :inviter_first_name do |invitation|
+ invitation.inviter.try(:first_name)
+ end
+
+ # Nil until the invitation is accepted by someone with an account.
+ attribute :invitee_name do |invitation|
+ invitation.invitee.try(:full_name).presence || invitation.invitee.try(:name)
+ end
+
+ attribute :invitee_first_name do |invitation|
+ invitation.invitee.try(:first_name)
+ end
+ end
+ end
+end
diff --git a/spree/core/app/serializers/spree/emails/store_serializer.rb b/spree/core/app/serializers/spree/emails/store_serializer.rb
new file mode 100644
index 0000000000..46a5f39a1b
--- /dev/null
+++ b/spree/core/app/serializers/spree/emails/store_serializer.rb
@@ -0,0 +1,26 @@
+module Spree
+ module Emails
+ class StoreSerializer < BaseSerializer
+ include Spree::ImagesHelper
+
+ LOGO_HEIGHT = 32
+
+ attributes :name, :address, :mail_from_address, :default_currency, :default_locale
+
+ attribute :url, &:storefront_url
+
+ attribute :support_email, &:support_email_address
+
+ attribute :logo_url do |store|
+ spree_image_url(store.email_logo, height: LOGO_HEIGHT)
+ end
+
+ # The width the logo shows at, from its proportions. Nil until the file
+ # has been analyzed, when the layout lets the width follow the height.
+ attribute :logo_width do |store|
+ width, height = store.email_logo&.metadata.to_h.values_at('width', 'height').map(&:to_f)
+ (LOGO_HEIGHT * width / height).round if height.to_f.positive?
+ end
+ end
+ end
+end
diff --git a/spree/core/app/serializers/spree/emails/user_serializer.rb b/spree/core/app/serializers/spree/emails/user_serializer.rb
new file mode 100644
index 0000000000..af57e7d6c6
--- /dev/null
+++ b/spree/core/app/serializers/spree/emails/user_serializer.rb
@@ -0,0 +1,12 @@
+module Spree
+ module Emails
+ # Staff and seller-panel users, as back-office emails address them.
+ class UserSerializer < BaseSerializer
+ attributes :email, :first_name, :last_name
+
+ attribute :name do |user|
+ user.try(:full_name).presence || user.try(:name).presence
+ end
+ end
+ end
+end
diff --git a/spree/core/app/serializers/spree/emails/webhook_endpoint_serializer.rb b/spree/core/app/serializers/spree/emails/webhook_endpoint_serializer.rb
new file mode 100644
index 0000000000..5eed4dc197
--- /dev/null
+++ b/spree/core/app/serializers/spree/emails/webhook_endpoint_serializer.rb
@@ -0,0 +1,16 @@
+module Spree
+ module Emails
+ # Never add the signing secret: an email must not carry it.
+ class WebhookEndpointSerializer < BaseSerializer
+ attributes :name, :url, :disabled_reason
+
+ attribute :display_name do |endpoint|
+ endpoint.name.presence || endpoint.url
+ end
+
+ attribute :disabled_at do |endpoint|
+ endpoint.disabled_at&.iso8601
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/emails/file_system.rb b/spree/core/app/services/spree/emails/file_system.rb
new file mode 100644
index 0000000000..503fe27d66
--- /dev/null
+++ b/spree/core/app/services/spree/emails/file_system.rb
@@ -0,0 +1,23 @@
+module Spree
+ module Emails
+ # Loads the partials templates pull in with `{% render 'spree/shared/line_item' %}`
+ # from `spree/shared/_line_item.liquid`, following Rails' partial naming.
+ class FileSystem
+ # @param resolver [Spree::Emails::TemplateResolver]
+ def initialize(resolver)
+ @resolver = resolver
+ end
+
+ # @param name [String]
+ # @return [String] the partial's source
+ def read_template_file(name)
+ path = @resolver.find_partial(name.to_s)
+ raise Liquid::FileSystemError, "No such email partial: #{name}" unless path
+
+ File.read(path)
+ rescue Spree::Emails::TemplateResolver::InvalidKey => e
+ raise Liquid::FileSystemError, e.message
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/emails/filters.rb b/spree/core/app/services/spree/emails/filters.rb
new file mode 100644
index 0000000000..b0fc49ead8
--- /dev/null
+++ b/spree/core/app/services/spree/emails/filters.rb
@@ -0,0 +1,84 @@
+module Spree
+ module Emails
+ # The filters email templates can use, in addition to Liquid's standard
+ # set. Names follow common Liquid conventions where the meaning is the same,
+ # is the Liquid most developers and agents already know.
+ module Filters
+ # @example {{ line_item.price | money }}
+ # @param amount [String, Numeric, nil]
+ # @param currency [String, nil] defaults to the email's currency
+ # @return [String]
+ def money(amount, currency = nil)
+ return '' if amount.blank?
+
+ Spree::Money.new(amount, currency: currency.presence || @context.registers[:currency]).to_s
+ end
+
+ # @example {{ order.total | money_with_currency }} # => "$10.00 USD"
+ # @return [String]
+ def money_with_currency(amount, currency = nil)
+ return '' if amount.blank?
+
+ Spree::Money.new(amount, currency: currency.presence || @context.registers[:currency], with_currency: true).to_s
+ end
+
+ # Formats a date in the store's time zone, never the server's. Takes a
+ # named format from the locale's `date.formats` (`long`, `short`,
+ # `default`), or a strftime pattern. A date with no time of day, such as
+ # "2026-12-31", is shown as that day in every zone.
+ #
+ # @example {{ order.completed_at | date: 'long' }}
+ # @example {{ 'now' | date: '%Y' }}
+ # @return [String]
+ def date(input, format = 'default')
+ value = parse_time(input)
+ return input.to_s if value.nil?
+
+ value = value.in_time_zone(time_zone) unless value.instance_of?(Date)
+ format = format.to_s
+
+ return value.strftime(format) if format.include?('%')
+
+ format = 'default' unless I18n.exists?("date.formats.#{format}")
+ I18n.l(value.to_date, format: format.to_sym)
+ end
+
+ # Translates one of Spree's own keys, with interpolation.
+ #
+ # @example {{ 'order_mailer.confirm_email.dear_customer' | t: name: order.customer_name }}
+ # @return [String]
+ def t(key, options = {})
+ interpolations = options.to_h.except('scope', 'default', :scope, :default).transform_keys(&:to_sym)
+
+ I18n.t(key.to_s, **interpolations, scope: :spree).to_s
+ end
+
+ # Marks a value as trusted HTML, so it is output without escaping. Only
+ # for HTML that was sanitized when it was written.
+ #
+ # @example {{ product.description_html | raw }}
+ # @return [ActiveSupport::SafeBuffer]
+ def raw(input)
+ input.to_s.html_safe
+ end
+
+ private
+
+ def parse_time(input)
+ case input
+ when Time, DateTime, ActiveSupport::TimeWithZone then input
+ when Date then input
+ when 'now', 'today' then Time.current
+ when /\A\d{4}-\d{2}-\d{2}\z/ then Date.iso8601(input)
+ when String then Time.iso8601(input)
+ end
+ rescue ArgumentError
+ nil
+ end
+
+ def time_zone
+ Time.find_zone(@context.registers[:store]&.preferred_timezone) || Time.zone
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/emails/liquid_context.rb b/spree/core/app/services/spree/emails/liquid_context.rb
new file mode 100644
index 0000000000..ffc2e75d91
--- /dev/null
+++ b/spree/core/app/services/spree/emails/liquid_context.rb
@@ -0,0 +1,48 @@
+module Spree
+ module Emails
+ # `{% render %}` gives each partial a fresh, isolated context, and Liquid
+ # does not carry strict mode into it.
+ #
+ # Inside a partial an argument the caller left out reads as empty, so
+ # partials can take optional arguments; a misspelled field on an object
+ # still raises under strict variables.
+ class LiquidContext < Liquid::Context
+ attr_accessor :optional_arguments
+
+ def new_isolated_subcontext
+ super.tap do |subcontext|
+ subcontext.strict_variables = strict_variables
+ subcontext.strict_filters = strict_filters
+ subcontext.optional_arguments = true
+ end
+ end
+
+ def find_variable(key, raise_on_not_found: true)
+ super(key, raise_on_not_found: raise_on_not_found && !optional_arguments)
+ end
+
+ # Filters that can only rearrange escaped text, never decode it into
+ # markup. `url_decode` and the like are left out on purpose: turning
+ # "%3Cb%3E" back into "<b>" must not produce trusted HTML.
+ MARKUP_PRESERVING_FILTERS = %w[
+ strip lstrip rstrip strip_newlines upcase downcase capitalize
+ append prepend replace replace_first replace_last remove remove_first remove_last
+ truncate truncatewords
+ ].freeze
+
+ # Captured text is already-escaped HTML. A filter from the list above
+ # keeps it that way: plain string arguments are escaped going in, and the
+ # result stays marked safe, so `{{ greeting | upcase }}` is not escaped a
+ # second time when printed. Any other filter's result is escaped again.
+ def invoke(method, *args)
+ input = args.first
+ return super unless registers[:escape_output] && input.is_a?(ActiveSupport::SafeBuffer)
+ return super(method, input.to_str, *args.drop(1)) unless MARKUP_PRESERVING_FILTERS.include?(method.to_s)
+
+ escaped = args.drop(1).map { |arg| arg.is_a?(String) ? ERB::Util.html_escape(arg) : arg }
+ result = super(method, input, *escaped)
+ result.is_a?(String) ? result.html_safe : result
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/emails/rendered_email.rb b/spree/core/app/services/spree/emails/rendered_email.rb
new file mode 100644
index 0000000000..9a66a19202
--- /dev/null
+++ b/spree/core/app/services/spree/emails/rendered_email.rb
@@ -0,0 +1,14 @@
+module Spree
+ module Emails
+ # The finished parts of one email, ready for Action Mailer.
+ class RenderedEmail
+ attr_reader :subject, :html, :text
+
+ def initialize(subject:, html:, text:)
+ @subject = subject
+ @html = html
+ @text = text
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/emails/renderer.rb b/spree/core/app/services/spree/emails/renderer.rb
new file mode 100644
index 0000000000..428263ce44
--- /dev/null
+++ b/spree/core/app/services/spree/emails/renderer.rb
@@ -0,0 +1,118 @@
+module Spree
+ module Emails
+ # Renders an email template into its subject, HTML and plain-text parts.
+ #
+ # Liquid fills in the data first, into the template and then the layout
+ # wrapping it; MJML then compiles the result into email-safe HTML. Every
+ # output is HTML-escaped unless a template marks it `| raw`, and a runaway
+ # template fails its one email rather than stalling the job queue.
+ class Renderer
+ LAYOUT = 'layouts/spree/base_mailer'.freeze
+
+ RESOURCE_LIMITS = {
+ render_length_limit: 2_000_000,
+ render_score_limit: 200_000,
+ assign_score_limit: 50_000
+ }.freeze
+
+ class << self
+ # The Liquid environment every email renders in: strict parsing and
+ # Spree's filters, isolated from any other Liquid the host app runs.
+ #
+ # @return [Liquid::Environment]
+ def environment
+ @environment ||= Liquid::Environment.build(error_mode: :strict) do |environment|
+ environment.register_filter(Spree::Emails::Filters)
+ environment.register_tag('capture', Spree::Core::Emails::EscapedOutput::Capture)
+ environment.register_tag('cycle', Spree::Core::Emails::EscapedOutput::Cycle)
+ end
+ end
+ end
+
+ # @param resolver [Spree::Emails::TemplateResolver]
+ # @param store [Spree::Store]
+ # @param currency [String, nil] what `money` formats in, defaults to the store's
+ def initialize(resolver:, store:, currency: nil)
+ @resolver = resolver
+ @store = store
+ @currency = currency.presence || store.default_currency
+ end
+
+ # @param template [Spree::Emails::Template] a Liquid template
+ # @param assigns [Hash] the template's variables
+ # @return [Spree::Emails::RenderedEmail]
+ def render(template, assigns = {})
+ assigns = prepare(assigns)
+ subject = subject_for(template, assigns)
+ body = render_liquid(template.body, assigns)
+ html = render_layout(body, assigns.merge('subject' => subject))
+
+ Spree::Emails::RenderedEmail.new(subject: subject, html: html, text: render_text(template, assigns, html))
+ end
+
+ # Wraps HTML a mailer rendered some other way — its own ERB views — in
+ # the email layout, so it carries the store's logo, header and footer.
+ #
+ # @param html [String] the email's body, trusted as rendered
+ # @param subject [String, nil]
+ # @return [String] the finished email HTML
+ def wrap(html, subject: nil)
+ body = %(<mj-section><mj-column><mj-text align="left">#{html}</mj-text></mj-column></mj-section>)
+
+ render_layout(body, prepare('subject' => subject.to_s))
+ end
+
+ private
+
+ def render_layout(body, assigns)
+ layout = @resolver.find(LAYOUT) || raise(ArgumentError, "Missing email layout #{LAYOUT}.liquid")
+
+ MRML.to_html(render_liquid(layout.body, assigns.merge('content_for_layout' => body.html_safe)))
+ end
+
+ def prepare(assigns)
+ base_assigns.merge(assigns.deep_stringify_keys)
+ end
+
+ # The subject is plain text for a mail header, so it is not HTML-escaped.
+ def subject_for(template, assigns)
+ render_liquid(template.subject.to_s, assigns, escape: false).squish
+ end
+
+ def render_text(template, assigns, html)
+ text_template = @resolver.find_text(template.key)
+ return Spree::Emails::TextConverter.call(html) unless text_template
+
+ render_liquid(text_template.body, assigns, escape: false)
+ end
+
+ def render_liquid(source, assigns, escape: true)
+ context = Spree::Emails::LiquidContext.build(
+ environment: self.class.environment,
+ environments: [assigns],
+ registers: { store: @store, currency: @currency, escape_output: escape,
+ file_system: Spree::Emails::FileSystem.new(@resolver) },
+ resource_limits: Liquid::ResourceLimits.new(RESOURCE_LIMITS),
+ rethrow_errors: true
+ )
+ context.strict_variables = strict?
+ context.strict_filters = true
+
+ Liquid::Template.parse(source, environment: self.class.environment).render!(context)
+ end
+
+ def base_assigns
+ @base_assigns ||= {
+ 'store' => JSON.parse(Spree::Emails::StoreSerializer.new(@store).serialize),
+ 'locale' => I18n.locale.to_s
+ }
+ end
+
+ # An unknown variable raises in development and test, so a typo fails
+ # a spec rather than rendering blank; production renders it empty.
+ def strict?
+ Rails.env.local?
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/emails/template.rb b/spree/core/app/services/spree/emails/template.rb
new file mode 100644
index 0000000000..010b5c97ee
--- /dev/null
+++ b/spree/core/app/services/spree/emails/template.rb
@@ -0,0 +1,40 @@
+module Spree
+ module Emails
+ # One Liquid email template on disk, with optional front matter.
+ class Template
+ FRONT_MATTER = /\A---\s*\n(.*?)\n---\s*(?:\n|\z)/m
+
+ attr_reader :key, :path
+
+ # @param key [String] the template key, e.g. "spree/order_mailer/confirm_email"
+ # @param path [String] the file on disk
+ def initialize(key:, path:)
+ @key = key
+ @path = path
+ end
+
+ # @return [String, nil] the subject line as Liquid, read from the front matter
+ def subject
+ front_matter['subject']
+ end
+
+ # @return [String] the template without its front matter
+ def body
+ source.sub(FRONT_MATTER, '')
+ end
+
+ private
+
+ def source
+ @source ||= File.read(path)
+ end
+
+ def front_matter
+ @front_matter ||= begin
+ match = source.match(FRONT_MATTER)
+ match ? YAML.safe_load(match[1]).to_h : {}
+ end
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/emails/template_resolver.rb b/spree/core/app/services/spree/emails/template_resolver.rb
new file mode 100644
index 0000000000..0a15ecf010
--- /dev/null
+++ b/spree/core/app/services/spree/emails/template_resolver.rb
@@ -0,0 +1,55 @@
+module Spree
+ module Emails
+ # Finds the Liquid template behind an email key, across the app's view
+ # paths: the host app's own file first, then the first one a gem ships.
+ # A later database step slots in front of this without changing any mailer.
+ class TemplateResolver
+ KEY_FORMAT = %r{\A[a-z0-9_]+(?:/[a-z0-9_]+)*\z}
+
+ class InvalidKey < ArgumentError; end
+
+ # @param view_paths [Array<String, Pathname>] directories to search, highest precedence first
+ def initialize(view_paths)
+ @view_paths = view_paths.map(&:to_s).uniq
+ end
+
+ # @param key [String] e.g. "spree/order_mailer/confirm_email"
+ # @return [Spree::Emails::Template, nil]
+ def find(key)
+ find_file(key, '.liquid')
+ end
+
+ # @param key [String]
+ # @return [Spree::Emails::Template, nil] the hand-written plain-text part, when there is one
+ def find_text(key)
+ find_file(key, '.text.liquid')
+ end
+
+ # @param name [String] a partial name, e.g. "spree/shared/line_item"
+ # @return [String, nil] the partial's path, "spree/shared/_line_item.liquid"
+ def find_partial(name)
+ *folders, file = name.to_s.split('/')
+ find_file([*folders, "_#{file}"].join('/'), '.liquid')&.path
+ end
+
+ private
+
+ attr_reader :view_paths
+
+ def find_file(key, extension)
+ validate!(key)
+
+ view_paths.each do |view_path|
+ path = File.join(view_path, "#{key}#{extension}")
+ return Template.new(key: key, path: path) if File.file?(path)
+ end
+
+ nil
+ end
+
+ def validate!(key)
+ raise InvalidKey, "Invalid email template name: #{key.inspect}" unless key.to_s.match?(KEY_FORMAT)
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/emails/text_converter.rb b/spree/core/app/services/spree/emails/text_converter.rb
new file mode 100644
index 0000000000..6655af43b0
--- /dev/null
+++ b/spree/core/app/services/spree/emails/text_converter.rb
@@ -0,0 +1,72 @@
+module Spree
+ module Emails
+ # Turns a rendered email's HTML into its plain-text part, keeping each
+ # link as "label (url)". Generating the text rather than writing it by
+ # hand means it can never drift from the HTML.
+ class TextConverter
+ BLOCK_ELEMENTS = %w[p div h1 h2 h3 h4 h5 h6 table tr ul ol li section blockquote].freeze
+ SKIPPED_ELEMENTS = %w[head style script title img].freeze
+ HIDDEN_STYLE = /display\s*:\s*none/i
+
+ # @param html [String]
+ # @return [String]
+ def self.call(html)
+ new(html).call
+ end
+
+ def initialize(html)
+ @document = Nokogiri::HTML(html)
+ end
+
+ # @return [String]
+ def call
+ output = +''
+ walk(@document.at('body') || @document, output)
+
+ output.lines.map { |line| line.squeeze(' ').strip }.join("\n").gsub(/\n{3,}/, "\n\n").strip + "\n"
+ end
+
+ private
+
+ def walk(node, output)
+ node.children.each do |child|
+ if child.text?
+ output << child.text.gsub(/\s+/, ' ')
+ elsif child.element?
+ element(child, output)
+ end
+ end
+ end
+
+ def element(node, output)
+ name = node.name.downcase
+ return if SKIPPED_ELEMENTS.include?(name) || node['style'].to_s.match?(HIDDEN_STYLE)
+
+ case name
+ when 'br' then output << "\n"
+ when 'a' then link(node, output)
+ when 'td', 'th'
+ walk(node, output)
+ output << ' '
+ else
+ block = BLOCK_ELEMENTS.include?(name)
+ output << "\n" if block
+ walk(node, output)
+ output << "\n" if block
+ end
+ end
+
+ def link(node, output)
+ label = +''
+ walk(node, label)
+ label = label.squeeze(' ').strip
+ href = node['href'].to_s.strip.delete_prefix('mailto:')
+
+ # A link with no text is a linked image, which has nothing to say in text.
+ return if label.blank?
+
+ output << (href.blank? || href == label ? label : "#{label} (#{href})")
+ end
+ end
+ end
+end
diff --git a/spree/core/app/views/active_storage/blobs/_blob.html.erb b/spree/core/app/views/active_storage/blobs/_blob.html.erb
deleted file mode 100644
index 04525029c3..0000000000
--- a/spree/core/app/views/active_storage/blobs/_blob.html.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
- <% if blob.representable? %>
- <%= spree_image_tag(blob, width: local_assigns[:in_gallery] ? 400 : 512, height: local_assigns[:in_gallery] ? 300 : 400) %>
- <% end %>
-
- <figcaption class="attachment__caption">
- <% if caption = blob.try(:caption) %>
- <%= caption %>
- <% else %>
- <span class="attachment__name"><%= blob.filename %></span>
- <span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
- <% end %>
- </figcaption>
-</figure>
diff --git a/spree/core/app/views/layouts/spree/base_mailer.html.erb b/spree/core/app/views/layouts/spree/base_mailer.html.erb
index 2a67a074dc..83c306c47d 100644
--- a/spree/core/app/views/layouts/spree/base_mailer.html.erb
+++ b/spree/core/app/views/layouts/spree/base_mailer.html.erb
@@ -1,43 +1,2 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html lang="<%= I18n.locale %>">
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
- <meta name="x-apple-disable-message-reformatting"/>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <meta name="color-scheme" content="light"/>
- <meta name="supported-color-schemes" content="light"/>
-
- <%= render partial: 'spree/shared/base_mailer_stylesheets' %>
- <%# Per-email styles — templates add their own via `content_for :head` %>
- <%= yield :head %>
- </head>
- <body class="email-bg" style="margin: 0; padding: 0; -webkit-text-size-adjust: none;" bgcolor="#FFFFFF">
- <table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation" bgcolor="#FFFFFF">
- <tr>
- <td align="center">
- <table class="email-content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <!-- Email Body -->
- <tr>
- <td class="email-card" bgcolor="#F6F6F6">
- <%= render partial: 'spree/shared/base_mailer_header' %>
- <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td class="content-cell f-fallback" align="left">
- <%= yield %>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <!-- Email Footer -->
- <tr>
- <td class="email-footer" align="center">
- <%= render partial: 'spree/shared/base_mailer_footer' %>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </body>
-</html>
+<%# Mailers that render their own ERB views get Spree's Liquid email layout around them. %>
+<%= render_in_email_layout(yield) %>
diff --git a/spree/core/app/views/layouts/spree/base_mailer.liquid b/spree/core/app/views/layouts/spree/base_mailer.liquid
new file mode 100644
index 0000000000..869e32b053
--- /dev/null
+++ b/spree/core/app/views/layouts/spree/base_mailer.liquid
@@ -0,0 +1,76 @@
+<mjml lang="{{ locale }}">
+ <mj-head>
+ <mj-title>{{ subject }}</mj-title>
+ <mj-attributes>
+ <mj-all font-family="Inter, Helvetica, Arial, sans-serif" />
+ <mj-section padding="0" />
+ <mj-column padding="0" />
+ <mj-text padding="0" color="#726A6A" font-size="14px" line-height="1.6" align="center" />
+ <mj-button background-color="#FFFFFF" border="1px solid #E8E9E9" border-radius="8px" color="#1F2222" font-size="15px" font-weight="500" line-height="1.6" inner-padding="12px 20px" padding="32px 0 0" />
+ <mj-table padding="0" color="#726A6A" font-size="14px" line-height="1.6" />
+ <mj-class name="heading" font-family="Geist, Inter, Helvetica, Arial, sans-serif" font-size="40px" font-weight="700" line-height="1.2" letter-spacing="-0.8px" color="#332C2C" css-class="heading" />
+ <mj-class name="greeting" padding="24px 0 0" font-size="15px" font-weight="500" color="#332C2C" />
+ <mj-class name="lead" padding="12px 0 0" />
+ <mj-class name="note" padding="24px 0 0" font-size="13px" css-class="note" />
+ <mj-class name="section-heading" padding="48px 0 16px" font-family="Geist, Inter, Helvetica, Arial, sans-serif" font-size="16px" font-weight="500" letter-spacing="-0.16px" align="left" />
+ <mj-class name="body" padding="16px 0 0" align="left" />
+ <mj-class name="footer" padding="12px 0 0" font-size="11px" line-height="1.5" />
+ </mj-attributes>
+ <mj-style>
+ @font-face { font-family: "Geist"; font-style: normal; font-weight: 500 700; src: url("https://fonts.gstatic.com/s/geist/v4/gyByhwUxId8gMEwcGFU.woff2") format("woff2"); }
+ @font-face { font-family: "Inter"; font-style: normal; font-weight: 400 450; src: url("https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuOKfMZg.ttf") format("truetype"); }
+ @font-face { font-family: "Inter"; font-style: normal; font-weight: 500; src: url("https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuI6fMZg.ttf") format("truetype"); }
+ @font-face { font-family: "Inter"; font-style: normal; font-weight: 600; src: url("https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuGKYMZg.ttf") format("truetype"); }
+ a { color: #332C2C; }
+ .hero > table { max-width: 420px; margin: 0 auto; }
+ .note a { color: #726A6A; word-break: break-all; }
+ .footer a { color: #726A6A; }
+ .item { width: 100%; background-color: #F0F0F0; border-radius: 16px; margin: 0 0 8px; }
+ .item_image { padding: 8px; width: 96px; }
+ .item_thumb { display: block; width: 80px; height: auto; border-radius: 12px; }
+ .item_thumb_placeholder { width: 80px; height: 80px; background-color: #E4E4E4; border-radius: 12px; }
+ .item_info { padding: 8px 16px 8px 8px; }
+ .item_name { font-size: 15px; line-height: 1.5; font-weight: 500; color: #332C2C; text-decoration: none; }
+ .item_meta { margin: 2px 0 0; font-size: 13px; line-height: 1.5; color: #726A6A; }
+ .item_amount { padding: 8px 16px 8px 8px; text-align: right; white-space: nowrap; }
+ .item_qty { margin: 0; font-size: 13px; line-height: 1.5; color: #726A6A; }
+ .item_price { margin: 2px 0 0; font-size: 15px; line-height: 1.5; font-weight: 500; color: #332C2C; }
+ .summary td { padding: 6px 0; font-size: 14px; line-height: 1.6; color: #726A6A; }
+ .summary_value { font-size: 15px; font-weight: 500; text-align: right; white-space: nowrap; color: #332C2C; }
+ .summary_sub { display: block; font-size: 13px; line-height: 1.5; }
+ .summary_total td { padding: 14px 0 0; border-top: 1px solid #E8E9E9; font-weight: 500; color: #332C2C; }
+ .summary_total .summary_value { font-weight: 600; }
+ .mailer_hero h1 { margin: 0; font-family: Geist, Inter, Helvetica, Arial, sans-serif; font-size: 40px; line-height: 1.2; letter-spacing: -0.8px; font-weight: 700; color: #332C2C; }
+ .mailer_hero p { margin: 12px 0 0; }
+ .mailer_hero .greeting { margin-top: 24px; font-size: 15px; font-weight: 500; color: #332C2C; }
+ .mailer_hero .sub { margin-top: 24px; font-size: 13px; }
+ @media only screen and (max-width: 600px) {
+ .heading div { font-size: 32px !important; letter-spacing: -0.64px !important; }
+ }
+ </mj-style>
+ </mj-head>
+ <mj-body background-color="#FFFFFF" width="640px">
+ <mj-wrapper background-color="#F6F6F6" padding="56px 24px">
+ <mj-section padding="0 0 32px">
+ <mj-column>
+ {% if store.logo_url and store.logo_width %}
+ <mj-image src="{{ store.logo_url }}" href="{{ store.url }}" alt="{{ store.name }}" width="{{ store.logo_width }}px" height="32px" padding="0" />
+ {% elsif store.logo_url %}
+ <mj-text><a href="{{ store.url }}"><img src="{{ store.logo_url }}" alt="{{ store.name }}" height="32" style="height: 32px; width: auto; border: 0;" /></a></mj-text>
+ {% else %}
+ <mj-text font-size="22px" font-weight="700" color="#332C2C" text-transform="uppercase"><a href="{{ store.url }}" style="color: #332C2C; text-decoration: none;">{{ store.name }}</a></mj-text>
+ {% endif %}
+ </mj-column>
+ </mj-section>
+ {{ content_for_layout }}
+ </mj-wrapper>
+ <mj-section padding="64px 24px">
+ <mj-column>
+ <mj-text font-size="13px" line-height="1.5" css-class="footer"><a href="{{ store.url }}" style="font-weight: 500; text-decoration: none;">{{ store.name }}</a></mj-text>
+ {% if store.address != blank %}<mj-text mj-class="footer">{{ store.address }}</mj-text>{% endif %}
+ {% if store.support_email != blank %}<mj-text mj-class="footer" css-class="footer"><a href="mailto:{{ store.support_email }}">{{ store.support_email }}</a></mj-text>{% endif %}
+ <mj-text mj-class="footer" padding="20px 0 0">&copy; {{ 'now' | date: '%Y' }} {{ store.name }}</mj-text>
+ </mj-column>
+ </mj-section>
+ </mj-body>
+</mjml>
diff --git a/spree/core/app/views/spree/admin_user_mailer/password_reset_email.html.erb b/spree/core/app/views/spree/admin_user_mailer/password_reset_email.html.erb
deleted file mode 100644
index 94959395b4..0000000000
--- a/spree/core/app/views/spree/admin_user_mailer/password_reset_email.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('admin_user_mailer.password_reset_email.action') %></h1>
- <p class="greeting"><%= Spree.t('admin_user_mailer.password_reset_email.greeting', name: @user.first_name.presence || @user.email) %></p>
- <p><%= Spree.t('admin_user_mailer.password_reset_email.instructions', store_name: @current_store.name) %></p>
- <%= render 'spree/shared/mailer_button', url: @reset_url, label: Spree.t('admin_user_mailer.password_reset_email.action') %>
- <p class="sub"><%= Spree.t('admin_user_mailer.password_reset_email.expiry_notice') %></p>
- <p class="sub"><%= Spree.t('admin_user_mailer.password_reset_email.ignore_notice') %></p>
-<% end %>
diff --git a/spree/core/app/views/spree/admin_user_mailer/password_reset_email.liquid b/spree/core/app/views/spree/admin_user_mailer/password_reset_email.liquid
new file mode 100644
index 0000000000..da10630db4
--- /dev/null
+++ b/spree/core/app/views/spree/admin_user_mailer/password_reset_email.liquid
@@ -0,0 +1,14 @@
+---
+subject: "{{ store.name }} {{ 'admin_user_mailer.password_reset_email.subject' | t }}"
+---
+{% 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>
diff --git a/spree/core/app/views/spree/export_mailer/export_done.html.erb b/spree/core/app/views/spree/export_mailer/export_done.html.erb
deleted file mode 100644
index 7e8527f1ce..0000000000
--- a/spree/core/app/views/spree/export_mailer/export_done.html.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('export_mailer.greeting', user_name: @export.user&.first_name) %></h1>
- <p><%= Spree.t('export_mailer.export_done.message') %></p>
- <% if @export.results_url.present? %>
- <%= render 'spree/shared/mailer_button', url: @export.results_url, label: @export.attachment.filename %>
- <% end %>
-<% end %>
diff --git a/spree/core/app/views/spree/export_mailer/export_done.liquid b/spree/core/app/views/spree/export_mailer/export_done.liquid
new file mode 100644
index 0000000000..af8e8fc028
--- /dev/null
+++ b/spree/core/app/views/spree/export_mailer/export_done.liquid
@@ -0,0 +1,12 @@
+---
+subject: "{{ 'export_mailer.export_done.subject' | t: export_number: export.number }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'export_mailer.greeting' | t: user_name: export.user.first_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'export_mailer.export_done.message' | t }}</mj-text>
+ {% if export.results_url != blank %}
+ <mj-button href="{{ export.results_url }}">{{ export.filename }}</mj-button>
+ {% endif %}
+ </mj-column>
+</mj-section>
diff --git a/spree/core/app/views/spree/import_mailer/import_done.html.erb b/spree/core/app/views/spree/import_mailer/import_done.html.erb
deleted file mode 100644
index d38c5fe0b2..0000000000
--- a/spree/core/app/views/spree/import_mailer/import_done.html.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('import_mailer.greeting', user_name: @import.user&.first_name) %></h1>
- <p><%= Spree.t('import_mailer.import_done.message', completed_count: @import.rows_status_counts['completed'] || 0) %></p>
- <% failed_count = @import.rows_status_counts['failed'] || 0 %>
- <% if failed_count > 0 %>
- <p><strong><%= Spree.t('import_mailer.import_done.failed_message', failed_count: failed_count) %></strong></p>
- <% end %>
- <% results_url = @import.results_page_url %>
- <% if results_url.present? %>
- <%= render 'spree/shared/mailer_button', url: results_url, label: Spree.t('import_mailer.import_done.view_results') %>
- <% end %>
-<% end %>
diff --git a/spree/core/app/views/spree/import_mailer/import_done.liquid b/spree/core/app/views/spree/import_mailer/import_done.liquid
new file mode 100644
index 0000000000..78816e677a
--- /dev/null
+++ b/spree/core/app/views/spree/import_mailer/import_done.liquid
@@ -0,0 +1,15 @@
+---
+subject: "{{ 'import_mailer.import_done.subject' | t: import_number: import.number }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'import_mailer.greeting' | t: user_name: import.user.first_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'import_mailer.import_done.message' | t: completed_count: import.completed_count }}</mj-text>
+ {% if import.failed_count > 0 %}
+ <mj-text mj-class="lead"><strong>{{ 'import_mailer.import_done.failed_message' | t: failed_count: import.failed_count }}</strong></mj-text>
+ {% endif %}
+ {% if import.results_url != blank %}
+ <mj-button href="{{ import.results_url }}">{{ 'import_mailer.import_done.view_results' | t }}</mj-button>
+ {% endif %}
+ </mj-column>
+</mj-section>
diff --git a/spree/core/app/views/spree/invitation_mailer/invitation_accepted.html.erb b/spree/core/app/views/spree/invitation_mailer/invitation_accepted.html.erb
deleted file mode 100644
index 640c32b56d..0000000000
--- a/spree/core/app/views/spree/invitation_mailer/invitation_accepted.html.erb
+++ /dev/null
@@ -1,4 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('invitation_mailer.greeting', user_name: @invitation.inviter.first_name) %></h1>
- <p><%= Spree.t('invitation_mailer.invitation_accepted.body', invitee_name: @invitation.invitee&.name, resource_name: @invitation.resource.name) %></p>
-<% end %>
diff --git a/spree/core/app/views/spree/invitation_mailer/invitation_accepted.liquid b/spree/core/app/views/spree/invitation_mailer/invitation_accepted.liquid
new file mode 100644
index 0000000000..e612bd70b6
--- /dev/null
+++ b/spree/core/app/views/spree/invitation_mailer/invitation_accepted.liquid
@@ -0,0 +1,9 @@
+---
+subject: "{{ 'invitation_mailer.invitation_accepted.subject' | t: invitee_name: invitation.invitee_name, resource_name: invitation.resource_name }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'invitation_mailer.greeting' | t: user_name: invitation.inviter_first_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'invitation_mailer.invitation_accepted.body' | t: invitee_name: invitation.invitee_name, resource_name: invitation.resource_name }}</mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/core/app/views/spree/invitation_mailer/invitation_email.html.erb b/spree/core/app/views/spree/invitation_mailer/invitation_email.html.erb
deleted file mode 100644
index 27ec8ed9e2..0000000000
--- a/spree/core/app/views/spree/invitation_mailer/invitation_email.html.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('invitation_mailer.invitation_email.subject', resource_name: @invitation.resource.name) %></h1>
- <p class="greeting"><%= Spree.t('invitation_mailer.greeting', user_name: @invitation.invitee&.first_name || @invitation.email) %></p>
- <p><%= Spree.t('invitation_mailer.invitation_email.body', inviter_name: @invitation.inviter.name, resource_name: @invitation.resource.name) %></p>
- <p><%= Spree.t('invitation_mailer.invitation_email.link_description') %></p>
- <% accept_url = if spree.respond_to?(:admin_invitation_url)
- spree.admin_invitation_url(@invitation, token: @invitation.token, host: @invitation.store.formatted_url)
- else
- main_app.admin_invitation_acceptance_url(@invitation)
- end %>
- <%= render 'spree/shared/mailer_button', url: accept_url, label: Spree.t(:accept) %>
-<% end %>
diff --git a/spree/core/app/views/spree/invitation_mailer/invitation_email.liquid b/spree/core/app/views/spree/invitation_mailer/invitation_email.liquid
new file mode 100644
index 0000000000..9823172862
--- /dev/null
+++ b/spree/core/app/views/spree/invitation_mailer/invitation_email.liquid
@@ -0,0 +1,13 @@
+---
+subject: "{{ 'invitation_mailer.invitation_email.subject' | t: resource_name: invitation.resource_name }}"
+---
+{% assign name = invitation.invitee_first_name | default: invitation.email %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'invitation_mailer.invitation_email.subject' | t: resource_name: invitation.resource_name }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'invitation_mailer.greeting' | t: user_name: name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'invitation_mailer.invitation_email.body' | t: inviter_name: invitation.inviter_name, resource_name: invitation.resource_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'invitation_mailer.invitation_email.link_description' | t }}</mj-text>
+ <mj-button href="{{ accept_url }}">{{ 'accept' | t }}</mj-button>
+ </mj-column>
+</mj-section>
diff --git a/spree/core/app/views/spree/seller_user_mailer/password_reset_email.html.erb b/spree/core/app/views/spree/seller_user_mailer/password_reset_email.html.erb
deleted file mode 100644
index b3b6e9d278..0000000000
--- a/spree/core/app/views/spree/seller_user_mailer/password_reset_email.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('seller_user_mailer.password_reset_email.action') %></h1>
- <p class="greeting"><%= Spree.t('seller_user_mailer.password_reset_email.greeting', name: @user.first_name.presence || @user.email) %></p>
- <p><%= Spree.t('seller_user_mailer.password_reset_email.instructions', store_name: @current_store.name) %></p>
- <%= render 'spree/shared/mailer_button', url: @reset_url, label: Spree.t('seller_user_mailer.password_reset_email.action') %>
- <p class="sub"><%= Spree.t('seller_user_mailer.password_reset_email.expiry_notice') %></p>
- <p class="sub"><%= Spree.t('seller_user_mailer.password_reset_email.ignore_notice') %></p>
-<% end %>
diff --git a/spree/core/app/views/spree/seller_user_mailer/password_reset_email.liquid b/spree/core/app/views/spree/seller_user_mailer/password_reset_email.liquid
new file mode 100644
index 0000000000..1d4840f2e1
--- /dev/null
+++ b/spree/core/app/views/spree/seller_user_mailer/password_reset_email.liquid
@@ -0,0 +1,14 @@
+---
+subject: "{{ store.name }} {{ 'seller_user_mailer.password_reset_email.subject' | t }}"
+---
+{% assign name = user.first_name | default: user.email %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'seller_user_mailer.password_reset_email.action' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'seller_user_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'seller_user_mailer.password_reset_email.instructions' | t: store_name: store.name }}</mj-text>
+ <mj-button href="{{ reset_url }}">{{ 'seller_user_mailer.password_reset_email.action' | t }}</mj-button>
+ <mj-text mj-class="note">{{ 'seller_user_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
+ <mj-text mj-class="note" padding="16px 0 0">{{ 'seller_user_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/core/app/views/spree/shared/_base_mailer_footer.html.erb b/spree/core/app/views/spree/shared/_base_mailer_footer.html.erb
deleted file mode 100644
index 4b29c0e84c..0000000000
--- a/spree/core/app/views/spree/shared/_base_mailer_footer.html.erb
+++ /dev/null
@@ -1,19 +0,0 @@
-<!-- You can override this template to design your own footer. -->
-<table width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td align="center">
- <div class="footer_content f-fallback">
- <p class="footer_brand">
- <%= link_to current_store.name, current_store.storefront_url %>
- </p>
- <% if current_store.address.present? %>
- <p class="footer_meta"><%= current_store.address %></p>
- <% end %>
- <% if current_store.customer_support_email.present? %>
- <p class="footer_meta"><%= mail_to current_store.customer_support_email %></p>
- <% end %>
- <p class="footer_note">&copy; <%= Time.current.year %> <%= current_store.name %></p>
- </div>
- </td>
- </tr>
-</table>
diff --git a/spree/core/app/views/spree/shared/_base_mailer_header.html.erb b/spree/core/app/views/spree/shared/_base_mailer_header.html.erb
deleted file mode 100644
index 614202835a..0000000000
--- a/spree/core/app/views/spree/shared/_base_mailer_header.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<!-- You can override this template to design your own header. -->
-<table width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td class="email-masthead" align="center">
- <%= render 'spree/shared/mailer_logo', logo: current_store.mailer_logo.attached? ? current_store.mailer_logo : current_store.logo, height: 32 %>
- </td>
- </tr>
-</table>
diff --git a/spree/core/app/views/spree/shared/_base_mailer_stylesheets.html.erb b/spree/core/app/views/spree/shared/_base_mailer_stylesheets.html.erb
deleted file mode 100644
index 5b749cb738..0000000000
--- a/spree/core/app/views/spree/shared/_base_mailer_stylesheets.html.erb
+++ /dev/null
@@ -1,399 +0,0 @@
-<style type="text/css" rel="stylesheet" media="all">
- /* Fonts ------------------------------ */
- /* Same files the react-email Studio templates load; Gmail strips these and falls back to Arial. */
-
- @font-face {
- font-family: "Geist";
- font-style: normal;
- font-weight: 500;
- src: url("https://fonts.gstatic.com/s/geist/v4/gyByhwUxId8gMEwcGFU.woff2") format("woff2");
- }
-
- @font-face {
- font-family: "Geist";
- font-style: normal;
- font-weight: 600;
- src: url("https://fonts.gstatic.com/s/geist/v4/gyByhwUxId8gMEwcGFU.woff2") format("woff2");
- }
-
- @font-face {
- font-family: "Geist";
- font-style: normal;
- font-weight: 700;
- src: url("https://fonts.gstatic.com/s/geist/v4/gyByhwUxId8gMEwcGFU.woff2") format("woff2");
- }
-
- @font-face {
- font-family: "Inter";
- font-style: normal;
- font-weight: 400;
- src: url("https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuOKfMZg.ttf") format("truetype");
- }
-
- @font-face {
- font-family: "Inter";
- font-style: normal;
- font-weight: 450;
- src: url("https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuOKfMZg.ttf") format("truetype");
- }
-
- @font-face {
- font-family: "Inter";
- font-style: normal;
- font-weight: 500;
- src: url("https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuI6fMZg.ttf") format("truetype");
- }
-
- @font-face {
- font-family: "Inter";
- font-style: normal;
- font-weight: 600;
- src: url("https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuGKYMZg.ttf") format("truetype");
- }
-
- /* Base ------------------------------ */
-
- body {
- width: 100% !important;
- height: 100%;
- margin: 0;
- -webkit-text-size-adjust: none;
- background-color: #FFFFFF;
- color: #726A6A;
- }
-
- a {
- color: #332C2C;
- }
-
- a img {
- border: none;
- }
-
- td {
- word-break: break-word;
- }
-
- .preheader {
- display: none !important;
- visibility: hidden;
- mso-hide: all;
- font-size: 1px;
- line-height: 1px;
- max-height: 0;
- max-width: 0;
- opacity: 0;
- overflow: hidden;
- }
-
- /* Type ------------------------------ */
-
- body,
- td,
- th {
- font-family: "Inter", Helvetica, Arial, sans-serif;
- }
-
- h1 {
- margin: 0 0 24px;
- font-family: "Geist", "Inter", Helvetica, Arial, sans-serif;
- color: #332C2C;
- font-size: 40px;
- line-height: 1.2;
- letter-spacing: -0.8px;
- font-weight: 700;
- text-align: center;
- }
-
- h2 {
- margin: 0 0 16px;
- font-family: "Geist", "Inter", Helvetica, Arial, sans-serif;
- color: #332C2C;
- font-size: 22px;
- line-height: 1.4;
- letter-spacing: -0.18px;
- font-weight: 500;
- text-align: center;
- }
-
- h3 {
- margin: 0 0 16px;
- font-family: "Geist", "Inter", Helvetica, Arial, sans-serif;
- color: #726A6A;
- font-size: 16px;
- line-height: 1.5;
- letter-spacing: -0.16px;
- font-weight: 500;
- text-align: left;
- }
-
- td,
- th {
- font-size: 14px;
- }
-
- p,
- ul,
- ol,
- blockquote {
- margin: 0 0 16px;
- font-size: 14px;
- line-height: 1.6;
- letter-spacing: -0.042px;
- font-weight: 450;
- color: #726A6A;
- }
-
- p.sub {
- font-size: 13px;
- color: #726A6A;
- }
-
- p.sub a {
- color: #726A6A;
- word-break: break-all;
- }
-
- p.strong {
- margin: 0;
- font-weight: 500;
- color: #332C2C;
- }
-
- /* Utilities ------------------------------ */
-
- .align-right {
- text-align: right;
- }
-
- .align-left {
- text-align: left;
- }
-
- .align-center {
- text-align: center;
- }
-
- /* Buttons ------------------------------ */
-
- .button {
- display: inline-block;
- background-color: #FFFFFF;
- border: 1px solid #E8E9E9;
- border-radius: 8px;
- padding: 12px 20px;
- font-size: 15px;
- line-height: 1.6;
- font-weight: 500;
- color: #1F2222 !important;
- text-decoration: none;
- -webkit-text-size-adjust: none;
- box-sizing: border-box;
- }
-
- .button--green {
- background-color: #22BC66;
- border-color: #22BC66;
- color: #FFFFFF !important;
- }
-
- .button--red {
- background-color: #FF6136;
- border-color: #FF6136;
- color: #FFFFFF !important;
- }
-
- @media only screen and (max-width: 500px) {
- .button {
- width: 100% !important;
- text-align: center !important;
- }
- }
-
- /* Hero ------------------------------ */
-
- .hero {
- width: 100%;
- text-align: center;
- }
-
- .hero_content {
- max-width: 420px;
- margin: 0 auto;
- }
-
- .hero h1 {
- margin: 0;
- }
-
- .hero p {
- margin: 12px 0 0;
- }
-
- .hero .greeting {
- margin: 24px 0 0;
- font-size: 15px;
- font-weight: 500;
- color: #332C2C;
- }
-
- .hero .sub {
- margin: 24px 0 0;
- }
-
- .hero .sub + .sub {
- margin: 16px 0 0;
- }
-
- /* Sections ------------------------------ */
-
- .section {
- width: 100%;
- margin: 48px 0 0;
- text-align: left;
- }
-
- .section .sub {
- margin: 16px 0 0;
- }
-
- /* Structure ------------------------------ */
-
- .email-wrapper {
- width: 100%;
- margin: 0;
- padding: 0;
- background-color: #FFFFFF;
- }
-
- .email-content {
- width: 100%;
- max-width: 640px;
- margin: 0 auto;
- padding: 0;
- }
-
- /* Masthead ----------------------- */
-
- .email-masthead {
- padding: 0 0 32px;
- text-align: center;
- }
-
- /* Body ------------------------------ */
-
- .email-card {
- background-color: #F6F6F6;
- padding: 56px 24px;
- }
-
- .email-footer {
- padding: 64px 24px;
- text-align: center;
- }
-
- .email-footer p {
- color: #726A6A;
- }
-
- .footer_content {
- max-width: 320px;
- margin: 0 auto;
- }
-
- .footer_brand {
- margin: 0;
- font-size: 13px;
- line-height: 1.5;
- letter-spacing: -0.13px;
- }
-
- .footer_brand a {
- color: #726A6A;
- font-weight: 500;
- text-decoration: none;
- }
-
- .footer_meta {
- margin: 12px 0 0;
- font-size: 11px;
- line-height: 1.5;
- letter-spacing: -0.11px;
- }
-
- .footer_meta a {
- color: #726A6A;
- }
-
- .footer_note {
- margin: 20px 0 0;
- font-size: 11px;
- line-height: 1.5;
- letter-spacing: -0.11px;
- color: #726A6A;
- }
-
- .body-action {
- width: 100%;
- margin: 32px auto 0;
- padding: 0;
- text-align: center;
- }
-
- /* Legacy class hooks ------------------------------ */
- /* Kept for host apps and extensions that override mailer templates with
- pre-5.6 markup; nothing in Spree itself uses these anymore. */
-
- .purchase,
- .purchase_content {
- width: 100%;
- margin: 0;
- }
-
- .purchase_item {
- padding: 10px 4px;
- color: #726A6A;
- font-size: 14px;
- line-height: 1.6;
- }
-
- .purchase_item--additional {
- font-size: 13px;
- color: #726A6A;
- }
-
- .purchase_total {
- margin: 0;
- text-align: right;
- font-weight: 500;
- color: #332C2C;
- }
-
- .purchase_total--name {
- margin: 0;
- text-align: right;
- color: #726A6A;
- }
-
- /* Media Queries ------------------------------ */
-
- @media only screen and (max-width: 600px) {
- .email-card {
- padding: 40px 16px !important;
- }
- .email-footer {
- padding: 48px 16px !important;
- }
- h1 {
- font-size: 32px !important;
- letter-spacing: -0.64px !important;
- }
- }
-</style>
-<!--[if mso]>
-<style type="text/css">
- .f-fallback {
- font-family: Arial, sans-serif;
- }
-</style>
-<![endif]-->
diff --git a/spree/core/app/views/spree/shared/_mailer_button.html.erb b/spree/core/app/views/spree/shared/_mailer_button.html.erb
index df7766befb..f40f6750ea 100644
--- a/spree/core/app/views/spree/shared/_mailer_button.html.erb
+++ b/spree/core/app/views/spree/shared/_mailer_button.html.erb
@@ -1,10 +1,9 @@
-<% button_class = local_assigns.fetch(:button_class, nil) %>
-<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation">
+<%# A call-to-action button for a custom mailer's ERB view. Locals: url, label. %>
+<table align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="margin: 32px auto 0;">
<tr>
<td align="center">
- <a href="<%= url %>" class="f-fallback button <%= button_class %>" target="_blank">
- <%= label %>
- </a>
+ <a href="<%= url %>" target="_blank"
+ style="display: inline-block; background-color: #FFFFFF; border: 1px solid #E8E9E9; border-radius: 8px; padding: 12px 20px; font-size: 15px; line-height: 1.6; font-weight: 500; color: #1F2222; text-decoration: none;"><%= label %></a>
</td>
</tr>
</table>
diff --git a/spree/core/app/views/spree/shared/_mailer_hero.html.erb b/spree/core/app/views/spree/shared/_mailer_hero.html.erb
index 70c0b787f2..00fe8be0bd 100644
--- a/spree/core/app/views/spree/shared/_mailer_hero.html.erb
+++ b/spree/core/app/views/spree/shared/_mailer_hero.html.erb
@@ -1,10 +1,11 @@
-<%# Centered hero block every mailer template opens with.
- Render as a layout so the template's headline/copy fills it:
- render layout: 'spree/shared/mailer_hero' do ... end %>
-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">
+<%# Centered hero block for a custom mailer's ERB view. Render it as a layout so
+ the view's heading and copy fill it:
+ render layout: 'spree/shared/mailer_hero' do ... end
+ Style its contents with h1, p.greeting and p.sub. %>
+<table class="mailer_hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
- <div class="hero_content f-fallback">
+ <div style="max-width: 420px; margin: 0 auto; text-align: center;">
<%= yield %>
</div>
</td>
diff --git a/spree/core/app/views/spree/shared/_mailer_logo.html.erb b/spree/core/app/views/spree/shared/_mailer_logo.html.erb
deleted file mode 100644
index ec4427d26d..0000000000
--- a/spree/core/app/views/spree/shared/_mailer_logo.html.erb
+++ /dev/null
@@ -1,41 +0,0 @@
-<% logo ||= current_store.mailer_logo.attached? ? current_store.mailer_logo : current_store.logo %>
-<% height ||= 64 %>
-<% logo_css ||= '' %>
-
-<%= link_to current_store.storefront_url, id: 'site-logo', style: "text-decoration: none;" do %>
- <span style="display: none;"><%= current_store.name %></span>
- <% if logo.present? && logo.attached? && logo.variable? %>
- <% aspect_ratio = spree_asset_aspect_ratio(logo) %>
- <% logo_style = "aspect-ratio: #{aspect_ratio};" %>
-
- <% if aspect_ratio.to_f > 10 %>
- <% logo_height = 16 %>
- <% elsif aspect_ratio.to_f > 5 %>
- <% logo_height = 25 %>
- <% elsif aspect_ratio.to_f < 3 %>
- <% logo_height = 32 %>
- <% else %>
- <% logo_height = 32 %>
- <% end %>
-
- <% if defined?(height) && height > 0 %>
- <% logo_style += "height: #{height}px;" %>
- <% cdn_height = height %>
- <% elsif aspect_ratio.to_f < 3 %>
- <% cdn_height = 64 %>
- <% logo_style += "height: 64px;" %>
- <% else %>
- <% cdn_height = 32 %>
- <% logo_style += "height: 32px;" %>
- <% end %>
-
- <% variant_options = spree_image_variant_options(resize_to_fit: [nil, cdn_height * 3]) %>
-
- <%= image_tag main_app.cdn_image_url(logo.variant(variant_options)),
- style: "#{logo_style} width: auto;",
- alt: current_store.name,
- height: cdn_height %>
- <% else %>
- <h1 style="margin: 0; font-size: 22px; font-weight: bold; text-align: center; text-transform: uppercase;"><%= current_store.name %></h1>
- <% end %>
-<% end %>
diff --git a/spree/core/app/views/spree/shared/_purchased_items_styles.html.erb b/spree/core/app/views/spree/shared/_purchased_items_styles.html.erb
deleted file mode 100644
index 10422fb63f..0000000000
--- a/spree/core/app/views/spree/shared/_purchased_items_styles.html.erb
+++ /dev/null
@@ -1,119 +0,0 @@
-<%# Per-email stylesheet for the line item tiles + order summary rows.
- Render it once at the top of any mailer template that uses these components —
- it lands in the layout <head> via `content_for :head`. %>
-<% content_for :head do %>
- <style type="text/css" rel="stylesheet" media="all">
- /* Line item tiles ------------------------------ */
-
- .item {
- width: 100%;
- background-color: #F0F0F0;
- border-radius: 16px;
- margin: 0 0 8px;
- }
-
- .item .item_image {
- padding: 8px;
- width: 96px;
- }
-
- .item .item_thumb {
- display: block;
- width: 80px;
- height: auto;
- border-radius: 12px;
- }
-
- .item .item_thumb_placeholder {
- width: 80px;
- height: 80px;
- background-color: #E4E4E4;
- border-radius: 12px;
- }
-
- .item .item_info {
- padding: 8px 16px 8px 8px;
- }
-
- .item .item_name {
- display: inline-block;
- font-size: 15px;
- line-height: 1.5;
- font-weight: 500;
- color: #332C2C;
- text-decoration: none;
- }
-
- .item .item_meta {
- margin: 2px 0 0;
- font-size: 13px;
- line-height: 1.5;
- color: #726A6A;
- }
-
- .item .item_amount {
- padding: 8px 16px 8px 8px;
- text-align: right;
- white-space: nowrap;
- }
-
- .item .item_qty {
- margin: 0;
- font-size: 13px;
- line-height: 1.5;
- color: #726A6A;
- }
-
- .item .item_price {
- margin: 2px 0 0;
- font-size: 15px;
- line-height: 1.5;
- font-weight: 500;
- color: #332C2C;
- }
-
- /* Summary rows ------------------------------ */
-
- .summary {
- width: 100%;
- margin: 16px 0 0;
- }
-
- .summary td {
- padding: 6px 0;
- font-size: 14px;
- line-height: 1.6;
- font-weight: 450;
- color: #726A6A;
- }
-
- .summary .summary_value {
- font-size: 15px;
- font-weight: 500;
- text-align: right;
- white-space: nowrap;
- }
-
- .summary .summary_sub {
- display: block;
- font-size: 13px;
- line-height: 1.5;
- color: #726A6A;
- }
-
- .summary .summary_strong {
- color: #332C2C;
- }
-
- .summary_total td {
- padding: 14px 0 0;
- border-top: 1px solid #E8E9E9;
- font-weight: 500;
- color: #332C2C;
- }
-
- .summary_total .summary_value {
- font-weight: 600;
- }
- </style>
-<% end %>
diff --git a/spree/core/app/views/spree/shared/_summary_row.liquid b/spree/core/app/views/spree/shared/_summary_row.liquid
new file mode 100644
index 0000000000..0074d179fa
--- /dev/null
+++ b/spree/core/app/views/spree/shared/_summary_row.liquid
@@ -0,0 +1,8 @@
+{%- comment -%}
+ One label/value row inside an <mj-table css-class="summary">.
+ Arguments: label (translation key when translate is true), value, optional sub (a second line under the label), optional total (the emphasized final row).
+{%- endcomment -%}
+<tr{% if total %} class="summary_total"{% endif %}>
+ <td valign="top">{% if translate %}{{ label | t }}{% else %}{{ label }}{% endif %}{% if sub != blank %} <span class="summary_sub">{{ sub }}</span>{% endif %}</td>
+ <td class="summary_value" align="right" valign="top">{{ value }}</td>
+</tr>
diff --git a/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.html.erb b/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.html.erb
deleted file mode 100644
index e35b2ec4ff..0000000000
--- a/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.html.erb
+++ /dev/null
@@ -1,51 +0,0 @@
-<%= render 'spree/shared/purchased_items_styles' %>
-
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('webhook_mailer.endpoint_disabled.heading') %></h1>
- <p><%= Spree.t('webhook_mailer.endpoint_disabled.message', endpoint_name: @endpoint.name || @endpoint.url) %></p>
-<% end %>
-
-<table class="section summary" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td valign="top">
- <span class="f-fallback"><%= Spree.t('webhook_mailer.endpoint_disabled.url_label') %></span>
- </td>
- <td class="summary_value summary_strong" align="right" valign="top">
- <span class="f-fallback"><%= @endpoint.url %></span>
- </td>
- </tr>
- <% if @endpoint.name.present? %>
- <tr>
- <td valign="top">
- <span class="f-fallback"><%= Spree.t('webhook_mailer.endpoint_disabled.name_label') %></span>
- </td>
- <td class="summary_value summary_strong" align="right" valign="top">
- <span class="f-fallback"><%= @endpoint.name %></span>
- </td>
- </tr>
- <% end %>
- <tr>
- <td valign="top">
- <span class="f-fallback"><%= Spree.t('webhook_mailer.endpoint_disabled.reason_label') %></span>
- </td>
- <td class="summary_value summary_strong" align="right" valign="top">
- <span class="f-fallback"><%= @endpoint.disabled_reason %></span>
- </td>
- </tr>
- <tr>
- <td valign="top">
- <span class="f-fallback"><%= Spree.t('webhook_mailer.endpoint_disabled.disabled_at_label') %></span>
- </td>
- <td class="summary_value summary_strong" align="right" valign="top">
- <span class="f-fallback"><%= @endpoint.disabled_at&.strftime('%Y-%m-%d %H:%M %Z') %></span>
- </td>
- </tr>
-</table>
-
-<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td>
- <p class="f-fallback"><%= Spree.t('webhook_mailer.endpoint_disabled.instructions') %></p>
- </td>
- </tr>
-</table>
diff --git a/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.liquid b/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.liquid
new file mode 100644
index 0000000000..43ba5d0914
--- /dev/null
+++ b/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.liquid
@@ -0,0 +1,21 @@
+---
+subject: "{{ 'webhook_mailer.endpoint_disabled.subject' | t: endpoint_name: endpoint.display_name }}"
+---
+{% assign disabled_at = endpoint.disabled_at | date: '%Y-%m-%d %H:%M %Z' %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'webhook_mailer.endpoint_disabled.heading' | t }}</mj-text>
+ <mj-text mj-class="lead">{{ 'webhook_mailer.endpoint_disabled.message' | t: endpoint_name: endpoint.display_name }}</mj-text>
+ </mj-column>
+</mj-section>
+<mj-section padding="48px 0 0">
+ <mj-column>
+ <mj-table css-class="summary">
+ {% render 'spree/shared/summary_row', label: 'webhook_mailer.endpoint_disabled.url_label', value: endpoint.url, translate: true %}
+ {% if endpoint.name != blank %}{% render 'spree/shared/summary_row', label: 'webhook_mailer.endpoint_disabled.name_label', value: endpoint.name, translate: true %}{% endif %}
+ {% render 'spree/shared/summary_row', label: 'webhook_mailer.endpoint_disabled.reason_label', value: endpoint.disabled_reason, translate: true %}
+ {% render 'spree/shared/summary_row', label: 'webhook_mailer.endpoint_disabled.disabled_at_label', value: disabled_at, translate: true %}
+ </mj-table>
+ <mj-text mj-class="body" padding="48px 0 0">{{ 'webhook_mailer.endpoint_disabled.instructions' | t }}</mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.text.erb b/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.text.erb
deleted file mode 100644
index d065c52653..0000000000
--- a/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.text.erb
+++ /dev/null
@@ -1,10 +0,0 @@
-<%= Spree.t('webhook_mailer.endpoint_disabled.heading') %>
-
-<%= Spree.t('webhook_mailer.endpoint_disabled.message', endpoint_name: @endpoint.name || @endpoint.url) %>
-
-URL: <%= @endpoint.url %>
-<% if @endpoint.name.present? %>Name: <%= @endpoint.name %><% end %>
-Reason: <%= @endpoint.disabled_reason %>
-Disabled at: <%= @endpoint.disabled_at&.strftime('%Y-%m-%d %H:%M %Z') %>
-
-<%= Spree.t('webhook_mailer.endpoint_disabled.instructions') %>
diff --git a/spree/api/config/initializers/alba.rb b/spree/core/config/initializers/alba.rb
similarity index 100%
rename from spree/api/config/initializers/alba.rb
rename to spree/core/config/initializers/alba.rb
diff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rb
index 3db704a06c..044a5f1aba 100644
--- a/spree/core/lib/spree/core.rb
+++ b/spree/core/lib/spree/core.rb
@@ -12,16 +12,21 @@ require 'action_mailer/railtie'
require 'acts_as_list'
+require 'alba'
require 'acts-as-taggable-on'
require 'awesome_nested_set'
require 'cancan'
require 'countries/global'
require 'friendly_id'
require 'jwt'
+require 'liquid'
+require 'spree/core/emails/escaped_output'
require 'monetize'
require 'mobility'
+require 'mrml'
require 'name_of_person'
require 'nokogiri'
+require 'oj'
require 'rails-html-sanitizer'
require 'paranoia'
require 'request_store'
diff --git a/spree/core/lib/spree/core/emails/escaped_output.rb b/spree/core/lib/spree/core/emails/escaped_output.rb
new file mode 100644
index 0000000000..8e001f0189
--- /dev/null
+++ b/spree/core/lib/spree/core/emails/escaped_output.rb
@@ -0,0 +1,60 @@
+module Spree
+ module Core
+ module Emails
+ # HTML-escapes what a Liquid email template prints, unless the value was
+ # marked `| raw`. Applied where output is written rather than through
+ # Liquid's global filter, which `{% assign %}` also runs through — that
+ # would escape a value once when assigned and again when printed, and
+ # turn assigned numbers and lists into strings.
+ #
+ # Switched on by the `escape_output` register, which Liquid hands down to
+ # every partial, so any other Liquid the host app runs is untouched.
+ module EscapedOutput
+ def self.active?(context)
+ context.registers[:escape_output]
+ end
+
+ # `{{ value }}` and `{% echo value %}`. Variables are not tags, so this
+ # is the one place Liquid itself has to be extended.
+ module Variable
+ def render_to_output_buffer(context, output)
+ return super unless EscapedOutput.active?(context)
+
+ write_escaped(render(context), output)
+ output
+ end
+
+ private
+
+ def write_escaped(value, output)
+ case value
+ when nil then nil
+ when Array then value.each { |item| write_escaped(item, output) }
+ else output << ERB::Util.html_escape(Liquid::Utils.to_s(value))
+ end
+ end
+ end
+
+ # A captured block was escaped as it rendered, so it is kept as safe
+ # HTML rather than escaped a second time when printed.
+ class Capture < Liquid::Capture
+ def render(context)
+ output = super
+ EscapedOutput.active?(context) ? output.html_safe : output
+ end
+ end
+
+ # `{% cycle %}` writes its values straight to the output.
+ class Cycle < Liquid::Cycle
+ def render_to_output_buffer(context, output)
+ return super unless EscapedOutput.active?(context)
+
+ output << ERB::Util.html_escape(super(context, +''))
+ end
+ end
+ end
+ end
+ end
+end
+
+Liquid::Variable.prepend(Spree::Core::Emails::EscapedOutput::Variable)
diff --git a/spree/core/lib/spree/testing_support/emails.rb b/spree/core/lib/spree/testing_support/emails.rb
new file mode 100644
index 0000000000..c12f2f9fa7
--- /dev/null
+++ b/spree/core/lib/spree/testing_support/emails.rb
@@ -0,0 +1,22 @@
+module Spree
+ module TestingSupport
+ module Emails
+ # The decoded text of every part of an email, HTML and plain text
+ # together. Rendered emails are quoted-printable on the wire, so the raw
+ # encoded body splits long lines and turns "=" into "=3D".
+ #
+ # @param message [Mail::Message, ActionMailer::MessageDelivery]
+ # @return [String]
+ def email_body(message)
+ message = message.message if message.respond_to?(:message) && !message.is_a?(Mail::Message)
+ parts = message.multipart? ? message.parts : [message]
+
+ parts.map(&:decoded).join("\n")
+ end
+ end
+ end
+end
+
+RSpec.configure do |config|
+ config.include Spree::TestingSupport::Emails
+end
diff --git a/spree/core/spec/fixtures/mailer_views/custom_views_probe_mailer/welcome_email.html.erb b/spree/core/spec/fixtures/mailer_views/custom_views_probe_mailer/welcome_email.html.erb
new file mode 100644
index 0000000000..1e66921cde
--- /dev/null
+++ b/spree/core/spec/fixtures/mailer_views/custom_views_probe_mailer/welcome_email.html.erb
@@ -0,0 +1,4 @@
+<%= render layout: 'spree/shared/mailer_hero' do %>
+ <h1>Welcome</h1>
+ <%= render 'spree/shared/mailer_button', url: 'https://example.com/start', label: 'Get started' %>
+<% end %>
diff --git a/spree/core/spec/mailers/spree/admin_user_mailer_spec.rb b/spree/core/spec/mailers/spree/admin_user_mailer_spec.rb
index 5a7a4ab011..0fe540fe46 100644
--- a/spree/core/spec/mailers/spree/admin_user_mailer_spec.rb
+++ b/spree/core/spec/mailers/spree/admin_user_mailer_spec.rb
@@ -16,7 +16,7 @@ describe Spree::AdminUserMailer, type: :mailer do
it 'links with the reset token' do
message = described_class.password_reset_email(admin_user, token, store)
- expect(message.body.encoded).to include("token=#{token}")
+ expect(email_body(message)).to include("token=#{token}")
end
# The token must never land on a storefront, which is where the store URL
@@ -26,13 +26,13 @@ describe Spree::AdminUserMailer, type: :mailer do
message = described_class.password_reset_email(admin_user, token, store)
- expect(message.body.encoded).to include("https://admin.example.com/reset-password?token=#{token}")
+ expect(email_body(message)).to include("https://admin.example.com/reset-password?token=#{token}")
end
it 'prefers the redirect URL when the API validated one (dashboard SPA)' do
message = described_class.password_reset_email(admin_user, token, store, redirect_url: 'https://admin.example.com/reset-password')
- expect(message.body.encoded).to include("https://admin.example.com/reset-password?token=#{token}")
+ expect(email_body(message)).to include("https://admin.example.com/reset-password?token=#{token}")
end
context 'when the admin has a dashboard language set' do
diff --git a/spree/core/spec/mailers/spree/base_mailer_spec.rb b/spree/core/spec/mailers/spree/base_mailer_spec.rb
index 1439494b65..29a5eb951d 100644
--- a/spree/core/spec/mailers/spree/base_mailer_spec.rb
+++ b/spree/core/spec/mailers/spree/base_mailer_spec.rb
@@ -12,9 +12,28 @@ class FromProbeMailer < Spree::BaseMailer
end
end
+class CustomViewsProbeMailer < Spree::BaseMailer
+ prepend_view_path Spree::Core::Engine.root.join('spec/fixtures/mailer_views')
+
+ def welcome_email(store)
+ @current_store = store
+ mail(to: '[email protected]', subject: 'Welcome aboard')
+ end
+end
+
describe Spree::BaseMailer, type: :mailer do
let!(:store) { @default_store }
+ describe 'a mailer rendering its own ERB views' do
+ let(:html) { CustomViewsProbeMailer.welcome_email(store).body.decoded }
+
+ it "wraps them in Spree's email layout, as before 6.0" do
+ expect(html).to include('Welcome', 'Get started', 'https://example.com/start')
+ expect(html).to include(store.name, store.support_email_address)
+ expect(html).not_to include('<mj-')
+ end
+ end
+
describe '#from_address' do
subject(:mailer) { described_class.new }
diff --git a/spree/core/spec/mailers/spree/export_mailer_spec.rb b/spree/core/spec/mailers/spree/export_mailer_spec.rb
index 35fb77ba86..01e55e5742 100644
--- a/spree/core/spec/mailers/spree/export_mailer_spec.rb
+++ b/spree/core/spec/mailers/spree/export_mailer_spec.rb
@@ -29,17 +29,17 @@ RSpec.describe Spree::ExportMailer, type: :mailer do
end
it 'includes export attachment filename' do
- expect(mail.body.encoded).to include(export.attachment.filename.to_s)
+ expect(email_body(mail)).to include(export.attachment.filename.to_s)
end
it 'includes the download link in the body' do
- expect(mail.body.encoded).to include("/admin/exports/#{export.id}")
+ expect(email_body(mail)).to include("/admin/exports/#{export.id}")
end
end
context 'without a results_url' do
it 'renders no download button' do
- expect(mail.body.encoded).not_to include(export.attachment.filename.to_s)
+ expect(email_body(mail)).not_to include(export.attachment.filename.to_s)
end
end
end
diff --git a/spree/core/spec/mailers/spree/import_mailer_spec.rb b/spree/core/spec/mailers/spree/import_mailer_spec.rb
index caa1d754aa..24c00c6a8d 100644
--- a/spree/core/spec/mailers/spree/import_mailer_spec.rb
+++ b/spree/core/spec/mailers/spree/import_mailer_spec.rb
@@ -24,7 +24,7 @@ RSpec.describe Spree::ImportMailer, type: :mailer do
end
it 'includes the completed row count' do
- expect(mail.body.encoded).to include(
+ expect(email_body(mail)).to include(
Spree.t('import_mailer.import_done.message', completed_count: 1)
)
end
@@ -35,7 +35,7 @@ RSpec.describe Spree::ImportMailer, type: :mailer do
end
it 'calls out the failed row count' do
- expect(mail.body.encoded).to include(
+ expect(email_body(mail)).to include(
Spree.t('import_mailer.import_done.failed_message', failed_count: 1)
)
end
@@ -47,7 +47,7 @@ RSpec.describe Spree::ImportMailer, type: :mailer do
end
it 'links to the wizard with the import param appended' do
- expect(mail.body.encoded).to include(
+ expect(email_body(mail)).to include(
"https://admin.example.com/store_abc/settings/imports?import=#{import.prefixed_id}"
)
end
@@ -55,7 +55,7 @@ RSpec.describe Spree::ImportMailer, type: :mailer do
context 'without a results_url' do
it 'renders no results button' do
- expect(mail.body.encoded).not_to include(
+ expect(email_body(mail)).not_to include(
Spree.t('import_mailer.import_done.view_results')
)
end
diff --git a/spree/core/spec/mailers/spree/invitation_mailer_spec.rb b/spree/core/spec/mailers/spree/invitation_mailer_spec.rb
index 53bee8473b..93e1942f14 100644
--- a/spree/core/spec/mailers/spree/invitation_mailer_spec.rb
+++ b/spree/core/spec/mailers/spree/invitation_mailer_spec.rb
@@ -25,7 +25,7 @@ RSpec.describe Spree::InvitationMailer, type: :mailer do
# delivering from a background job.
it 'brands the email with the invitation store, not the default store' do
expect(mail.from).to eq(['[email protected]'])
- expect(mail.body.encoded).to include('Second Store')
+ expect(email_body(mail)).to include('Second Store')
end
end
@@ -60,9 +60,9 @@ RSpec.describe Spree::InvitationMailer, type: :mailer do
end
it 'uses spree.admin_invitation_url for the accept link' do
- expect(mail.body.encoded).to include(Spree.t(:accept))
- expect(mail.body.encoded).to include(legacy_admin_url)
- expect(mail.body.encoded).not_to include(spa_acceptance_url)
+ expect(email_body(mail)).to include(Spree.t(:accept))
+ expect(email_body(mail)).to include(legacy_admin_url)
+ expect(email_body(mail)).not_to include(spa_acceptance_url)
end
end
@@ -78,13 +78,13 @@ RSpec.describe Spree::InvitationMailer, type: :mailer do
end
it 'uses the admin_invitation_acceptance helper for the accept link' do
- expect(mail.body.encoded).to include(Spree.t(:accept))
- expect(mail.body.encoded).to include(spa_acceptance_url)
- expect(mail.body.encoded).not_to include(legacy_admin_url)
+ expect(email_body(mail)).to include(Spree.t(:accept))
+ expect(email_body(mail)).to include(spa_acceptance_url)
+ expect(email_body(mail)).not_to include(legacy_admin_url)
end
it 'honors Spree::Config[:admin_url] in the rendered URL' do
- expect(mail.body.encoded).to include(
+ expect(email_body(mail)).to include(
"https://admin.example.com/accept-invitation/#{invitation.prefixed_id}"
)
end
@@ -103,10 +103,10 @@ RSpec.describe Spree::InvitationMailer, type: :mailer do
after { Spree::Config[:seller_panel_url] = nil }
it 'points at the seller panel rather than the dashboard' do
- expect(mail.body.encoded).to include(
+ expect(email_body(mail)).to include(
"https://sellers.example.com/accept-invitation/#{invitation.prefixed_id}"
)
- expect(mail.body.encoded).not_to include('https://admin.example.com/accept-invitation')
+ expect(email_body(mail)).not_to include('https://admin.example.com/accept-invitation')
end
end
@@ -131,7 +131,7 @@ RSpec.describe Spree::InvitationMailer, type: :mailer do
# Falls through to the store's storefront URL — keeps the dummy/test
# app + all-in-one installs working without any Spree::Config setup.
it 'falls back to the storefront URL' do
- expect(mail.body.encoded).to match(%r{accept-invitation/#{invitation.prefixed_id}\?token=#{invitation.token}})
+ expect(email_body(mail)).to match(%r{accept-invitation/#{invitation.prefixed_id}\?token=#{invitation.token}})
end
end
end
@@ -152,7 +152,7 @@ RSpec.describe Spree::InvitationMailer, type: :mailer do
end
it 'includes the invitee name in the body' do
- expect(mail.body.encoded).to include(invitee.name)
+ expect(email_body(mail)).to include(invitee.name)
end
it 'sends to the correct recipient' do
diff --git a/spree/core/spec/mailers/spree/seller_user_mailer_spec.rb b/spree/core/spec/mailers/spree/seller_user_mailer_spec.rb
index 87d2228223..74c6fab032 100644
--- a/spree/core/spec/mailers/spree/seller_user_mailer_spec.rb
+++ b/spree/core/spec/mailers/spree/seller_user_mailer_spec.rb
@@ -16,7 +16,7 @@ describe Spree::SellerUserMailer, type: :mailer do
it 'links with the reset token' do
message = described_class.password_reset_email(seller_user, token, store)
- expect(message.body.encoded).to include("token=#{token}")
+ expect(email_body(message)).to include("token=#{token}")
end
it 'prefers the redirect URL when the API validated one' do
@@ -24,7 +24,7 @@ describe Spree::SellerUserMailer, type: :mailer do
seller_user, token, store, redirect_url: 'https://sellers.example.com/reset-password'
)
- expect(message.body.encoded).to include("https://sellers.example.com/reset-password?token=#{token}")
+ expect(email_body(message)).to include("https://sellers.example.com/reset-password?token=#{token}")
end
# The point of the separate mailer: without a redirect URL the link must
@@ -35,7 +35,7 @@ describe Spree::SellerUserMailer, type: :mailer do
message = described_class.password_reset_email(seller_user, token, store)
- expect(message.body.encoded).to include("https://sellers.example.com/reset-password?token=#{token}")
+ expect(email_body(message)).to include("https://sellers.example.com/reset-password?token=#{token}")
end
end
end
diff --git a/spree/core/spec/services/spree/emails/renderer_spec.rb b/spree/core/spec/services/spree/emails/renderer_spec.rb
new file mode 100644
index 0000000000..b22d45d645
--- /dev/null
+++ b/spree/core/spec/services/spree/emails/renderer_spec.rb
@@ -0,0 +1,157 @@
+require 'spec_helper'
+
+describe Spree::Emails::Renderer do
+ subject(:renderer) { described_class.new(resolver: resolver, store: store) }
+
+ let(:store) { @default_store }
+ let(:views) { Pathname.new(Dir.mktmpdir) }
+ let(:resolver) do
+ Spree::Emails::TemplateResolver.new([views, Spree::Core::Engine.root.join('app/views')])
+ end
+
+ after { FileUtils.remove_entry(views) }
+
+ def write(key, source)
+ path = views.join(key)
+ FileUtils.mkdir_p(path.dirname)
+ File.write(path, source)
+ end
+
+ def render(body, assigns = {}, subject: 'Test email')
+ write('spree/test_mailer/test_email.liquid', "---\nsubject: \"#{subject}\"\n---\n#{body}")
+ renderer.render(resolver.find('spree/test_mailer/test_email'), assigns)
+ end
+
+ def section(content)
+ "<mj-section><mj-column><mj-text>#{content}</mj-text></mj-column></mj-section>"
+ end
+
+ it 'renders the subject from the front matter and the body inside the layout' do
+ email = render(section('Body for {{ name }}'), { name: 'Ann' }, subject: 'Hello {{ name }}')
+
+ expect(email.subject).to eq('Hello Ann')
+ expect(email.html).to include('Body for Ann')
+ expect(email.html).to include(store.name)
+ expect(email.html).not_to include('<mj-', '{{', '{%')
+ end
+
+ it 'generates the plain-text part from the HTML, keeping links' do
+ email = render(section('<a href="https://example.com/reset">Reset</a>'), { name: 'Ann' })
+
+ expect(email.text).to include('Reset (https://example.com/reset)')
+ expect(email.text).not_to include('<')
+ end
+
+ it 'uses a hand-written text part when the template has one' do
+ write('spree/test_mailer/test_email.text.liquid', 'Plain {{ name }} & co')
+
+ expect(render(section('x'), { name: 'Ann' }).text).to eq('Plain Ann & co')
+ end
+
+ describe 'escaping' do
+ let(:payload) { '<a href="https://evil.test">Click to verify</a>' }
+
+ it 'escapes every output, including values assigned first' do
+ email = render(section('{{ name }} {% assign copy = name %}{{ copy }}'), { name: payload })
+
+ expect(email.html).not_to include('<a href="https://evil.test">')
+ expect(email.html.scan('&lt;a href=').size).to eq(2)
+ end
+
+ it 'escapes captured text once' do
+ email = render(section('{% capture greeting %}Hi {{ name }}{% endcapture %}{{ greeting }}'), { name: "O'Brien & Co" })
+
+ expect(email.html).to include('Hi O&#39;Brien &amp; Co')
+ end
+
+ it 'keeps captured text escaped once after trimming it' do
+ email = render(section('{% capture greeting %} Hi {{ name }} {% endcapture %}{{ greeting | strip }}'), { name: 'Smith & Co' })
+
+ expect(email.html).to include('Hi Smith &amp; Co')
+ end
+
+ it 'escapes captured text once through any filter, and escapes the filter arguments' do
+ email = render(section("{% capture greeting %}Hi {{ name }}{% endcapture %}{{ greeting | append: ' & <b>more</b>' }}"), { name: 'Smith & Co' })
+
+ expect(email.html).to include('Hi Smith &amp; Co &amp; &lt;b&gt;more&lt;/b&gt;')
+ end
+
+ it 'never trusts captured text a filter decoded into markup' do
+ email = render(section('{% capture note %}{{ text }}{% endcapture %}{{ note | url_decode }}'), { text: '%3Cb%3Ebold%3C%2Fb%3E' })
+
+ expect(email.html).to include('&lt;b&gt;bold&lt;/b&gt;')
+ expect(email.html).not_to include('<b>bold</b>')
+ end
+
+ it 'escapes what cycle writes' do
+ email = render(section("{% cycle name, 'x' %}"), { name: payload })
+
+ expect(email.html).not_to include('<a href="https://evil.test">')
+ end
+
+ it 'escapes what a partial outputs' do
+ write('spree/shared/_greeting.liquid', '{{ who }}')
+
+ email = render(section("{% render 'spree/shared/greeting', who: name %}"), { name: payload })
+
+ expect(email.html).not_to include('<a href="https://evil.test">')
+ expect(email.html).to include('&lt;a href=')
+ end
+
+ it 'does not escape a value marked raw' do
+ expect(render(section('{{ html | raw }}'), { html: '<strong>bold</strong>' }).html).to include('<strong>bold</strong>')
+ end
+
+ it 'keeps the subject as plain text' do
+ expect(render(section('x'), { name: 'Tom & Jerry' }, subject: 'Hello {{ name }}').subject).to eq('Hello Tom & Jerry')
+ end
+
+ it 'escapes interpolated translations once' do
+ email = render(section("{{ 'admin_user_mailer.password_reset_email.greeting' | t: name: name }}"), { name: 'Ann <b>' })
+
+ expect(email.html).to include('Ann &lt;b&gt;')
+ expect(email.text).to include('Ann <b>')
+ end
+ end
+
+ it 'raises on a misspelled field, so a typo fails a spec rather than rendering blank' do
+ expect { render(section('{{ order.nubmer }}'), { order: { number: 'R1' } }) }.to raise_error(Liquid::UndefinedVariable)
+ end
+
+ it 'lets a partial take optional arguments' do
+ write('spree/shared/_optional.liquid', '[{{ maybe }}]')
+
+ expect(render(section("{% render 'spree/shared/optional' %}"), { name: 'Ann' }).html).to include('[]')
+ end
+
+ it 'refuses a partial name that leaves the view paths' do
+ expect { render(section("{% render '../../etc/passwd' %}")) }.to raise_error(Liquid::FileSystemError)
+ end
+
+ it 'fails a runaway template instead of rendering it' do
+ expect { render(section('{% for i in (1..10000000) %}{{ i }}{% endfor %}')) }.to raise_error(Liquid::MemoryError)
+ end
+
+ describe 'filters' do
+ it 'formats money in the email currency' do
+ eur = described_class.new(resolver: resolver, store: store, currency: 'EUR')
+ write('spree/test_mailer/test_email.liquid', "---\nsubject: \"{{ amount | money }} {{ amount | money_with_currency }}\"\n---\n#{section('x')}")
+
+ expect(eur.render(resolver.find('spree/test_mailer/test_email'), amount: '10.5').subject).to eq('€10.50 €10.50 EUR')
+ end
+
+ it "formats dates in the store's time zone" do
+ allow(store).to receive(:preferred_timezone).and_return('Pacific/Auckland')
+
+ email = render(section('x'), { at: '2026-01-01T20:00:00Z' }, subject: "{{ at | date: '%Y-%m-%d %H:%M' }} {{ at | date: 'long' }}")
+
+ expect(email.subject).to eq('2026-01-02 09:00 January 02, 2026')
+ end
+
+ it 'formats a date with no time of day as that day' do
+ allow(store).to receive(:preferred_timezone).and_return('Pacific/Honolulu')
+
+ expect(render(section('x'), { on: '2026-12-31' }, subject: "{{ on | date: 'long' }}").subject).to eq('December 31, 2026')
+ end
+ end
+end
diff --git a/spree/core/spec/services/spree/emails/template_resolver_spec.rb b/spree/core/spec/services/spree/emails/template_resolver_spec.rb
new file mode 100644
index 0000000000..b651828660
--- /dev/null
+++ b/spree/core/spec/services/spree/emails/template_resolver_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe Spree::Emails::TemplateResolver do
+ let(:app_views) { Pathname.new(Dir.mktmpdir) }
+ let(:gem_views) { Pathname.new(Dir.mktmpdir) }
+ let(:key) { 'spree/order_mailer/confirm_email' }
+ let(:resolver) { described_class.new([app_views, gem_views]) }
+
+ after { [app_views, gem_views].each { |dir| FileUtils.remove_entry(dir) } }
+
+ def write(root, file)
+ path = root.join(file)
+ FileUtils.mkdir_p(path.dirname)
+ File.write(path, '')
+ path.to_s
+ end
+
+ before { write(gem_views, "#{key}.liquid") }
+
+ it "falls back to the gem's template" do
+ expect(resolver.find(key).path).to eq(gem_views.join("#{key}.liquid").to_s)
+ end
+
+ it "prefers the app's template" do
+ app_liquid = write(app_views, "#{key}.liquid")
+
+ expect(resolver.find(key).path).to eq(app_liquid)
+ end
+
+ it 'never picks up an ERB view' do
+ write(app_views, "#{key}.html.erb")
+
+ expect(resolver.find(key).path).to end_with('.liquid')
+ end
+
+ it 'finds a partial named without a folder' do
+ partial = write(gem_views, '_greeting.liquid')
+
+ expect(resolver.find_partial('greeting')).to eq(partial)
+ end
+
+ it 'refuses a key that could leave the view paths' do
+ expect { resolver.find('../secrets') }.to raise_error(described_class::InvalidKey)
+ end
+end
diff --git a/spree/core/spec/spec_helper.rb b/spree/core/spec/spec_helper.rb
index 8554f86bce..c1bf9190c4 100644
--- a/spree/core/spec/spec_helper.rb
+++ b/spree/core/spec/spec_helper.rb
@@ -55,6 +55,7 @@ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
require 'spree/testing_support/i18n' if ENV['CHECK_TRANSLATIONS']
require 'spree/testing_support/action_text'
+require 'spree/testing_support/emails'
require 'spree/testing_support/factories'
require 'spree/testing_support/jobs'
require 'spree/testing_support/store'
diff --git a/spree/core/spree_core.gemspec b/spree/core/spree_core.gemspec
index 1efc928568..dac32aa814 100644
--- a/spree/core/spree_core.gemspec
+++ b/spree/core/spree_core.gemspec
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
s.add_dependency 'acts_as_list', '>= 0.8'
+ s.add_dependency 'alba', '~> 3.0'
s.add_dependency 'acts-as-taggable-on'
s.add_dependency 'awesome_nested_set', '~> 3.3', '>= 3.3.1'
s.add_dependency 'benchmark' # needed for ruby 4.0 and benchmark gem
@@ -49,10 +50,13 @@ Gem::Specification.new do |s|
# once activesupport passes those options as keywords.
s.add_dependency 'json', '< 3'
s.add_dependency 'jwt', '~> 3.1'
+ s.add_dependency 'liquid', '~> 5.14'
s.add_dependency 'money', '~> 6.13'
+ s.add_dependency 'mrml', '~> 1.10'
s.add_dependency 'monetize', '~> 1.9'
s.add_dependency 'name_of_person', '~> 1.1'
s.add_dependency 'nokogiri', '~> 1.18'
+ s.add_dependency 'oj', '~> 3.16'
s.add_dependency 'ostruct'
s.add_dependency 'paranoia', '>= 2.4'
s.add_dependency 'loofah', '~> 2.21'
diff --git a/spree/emails/README.md b/spree/emails/README.md
index be9d7e286b..895dace66d 100644
--- a/spree/emails/README.md
+++ b/spree/emails/README.md
@@ -8,11 +8,11 @@ Spree Emails provides transactional email templates and mailers for Spree Commer
This gem includes:
-- **Order Mailer** - Order confirmation and cancellation emails
-- **Shipment Mailer** - Shipping and delivery notifications
-- **Reimbursement Mailer** - Refund notifications
-- **Event Subscribers** - Automatic email triggers on store events
-- **Email Templates** - Customizable HTML and text templates
+- **Mailers** for order confirmation, cancellation and payment links, multi-seller purchase confirmations, fulfillment notices, refunds, digital downloads, customer password resets and data exports, newsletter confirmation, company invitations and seller status changes
+- **Event subscribers** that send them when store events happen
+- **Liquid templates** written in MJML, one per email, that you can override
+
+Staff emails (password resets, invitations, import and export results, disabled webhooks) live in `spree_core` and render the same way.
## Installation
@@ -20,22 +20,6 @@ This gem includes:
bundle add spree_emails
```
-## Email Types
-
-### Order Emails
-
-- **Order Confirmation** - Sent when an order is completed
-- **Order Cancellation** - Sent when an order is cancelled
-
-### Shipment Emails
-
-- **Shipment Notification** - Sent when a shipment is shipped
-- **Delivery Confirmation** - Sent when tracking shows delivered
-
-### Reimbursement Emails
-
-- **Refund Notification** - Sent when a reimbursement is processed
-
## Configuration
Transactional emails are controlled per-store via the `send_consumer_transactional_emails` preference. This can be configured in the admin dashboard under Store Settings, or programmatically:
@@ -69,72 +53,44 @@ config.action_mailer.smtp_settings = {
## Customization
-### Overriding Templates
-
-Copy email templates to your application:
+### Overriding templates
-```bash
-# Copy all email templates
-cp -r $(bundle show spree_emails)/app/views/spree/mailer app/views/spree/
+Every email renders from a Liquid template at its Rails view path. To change one, create the file at the same path in your app — for example `app/views/spree/order_mailer/confirm_email.liquid` — starting from the copy in this gem's `app/views`. The layout around every email is `app/views/layouts/spree/base_mailer.liquid`.
-# Or copy specific templates
-cp $(bundle show spree_emails)/app/views/spree/mailer/order_mailer/confirm_email.html.erb \
- app/views/spree/mailer/order_mailer/
-```
+Templates read plain data from serializers, never models: see the [email templates guide](https://spreecommerce.org/docs/developer/customization/emails) for the layout, partials, filters and escaping, and the [variable reference](https://spreecommerce.org/docs/developer/customization/email-variables) for what each template receives.
-### Template Structure
-
-```
-app/views/spree/mailer/
-├── order_mailer/
-│ ├── confirm_email.html.erb
-│ ├── confirm_email.text.erb
-│ ├── cancel_email.html.erb
-│ └── cancel_email.text.erb
-├── shipment_mailer/
-│ ├── shipped_email.html.erb
-│ └── shipped_email.text.erb
-└── reimbursement_mailer/
- ├── reimbursement_email.html.erb
- └── reimbursement_email.text.erb
-```
+Mailers of your own that render ERB views keep working, wrapped in the same layout.
-### Custom Mailer
+### Adding new email types
-Create custom mailers by extending Spree's base mailer:
+Extend Spree's base mailer and render a Liquid template at the action's view path, passing the data it needs:
```ruby
-# app/mailers/spree/order_mailer_decorator.rb
+# app/mailers/spree/custom_mailer.rb
module Spree
- module OrderMailerDecorator
- def confirm_email(order, resend = false)
- @custom_data = fetch_custom_data(order)
- super
- end
-
- private
+ class CustomMailer < BaseMailer
+ def welcome_email(customer, store)
+ @current_store = store
- def fetch_custom_data(order)
- # Custom logic
+ with_store_locale(@current_store) do
+ mail_template({ customer: email_data(customer, Spree.api.customer_serializer) }, to: customer.email)
+ end
end
end
end
-
-Spree::OrderMailer.prepend(Spree::OrderMailerDecorator)
```
-### Adding New Email Types
-
-```ruby
-# app/mailers/spree/custom_mailer.rb
-module Spree
- class CustomMailer < BaseMailer
- def welcome_email(user)
- @user = user
- mail(to: @user.email, subject: 'Welcome to our store!')
- end
- end
-end
+And its template, `app/views/spree/custom_mailer/welcome_email.liquid` (the front matter must open the file):
+
+```liquid
+---
+subject: "Welcome to {{ store.name }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">Welcome, {{ customer.first_name }}!</mj-text>
+ </mj-column>
+</mj-section>
```
## Event Integration
@@ -152,7 +108,7 @@ module MyApp
user = Spree.customer_class.find_by(id: user_id)
return unless user
- Spree::CustomMailer.welcome_email(user).deliver_later
+ Spree::CustomMailer.welcome_email(user, Spree::Store.default).deliver_later
end
end
end
diff --git a/spree/emails/app/helpers/spree/base_helper.rb b/spree/emails/app/helpers/spree/base_helper.rb
deleted file mode 100644
index c03cf42c25..0000000000
--- a/spree/emails/app/helpers/spree/base_helper.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-module Spree
- module BaseHelper
- # returns the URL of an object on the storefront
- # @param resource [Spree::Product, Spree::Category] the resource to get the URL for
- # @param options [Hash] the options for the URL
- # @option options [String] :locale the locale of the resource, defaults to I18n.locale
- # @option options [String] :store the store of the resource, defaults to current_store
- # @option options [String] :relative whether to use the relative URL, defaults to false
- # @option options [String] :preview_id the preview ID of the resource, usually the ID of the resource
- # @option options [String] :variant_id the variant ID of the resource, usually the ID of the variant (only used for products)
- # @return [String] the URL of the resource
- def spree_storefront_resource_url(resource, options = {})
- store = options[:store] || current_store
-
- base_url = if options[:relative]
- ''
- else
- store.storefront_url
- end
-
- localize = if options[:locale].present?
- "/#{options[:locale]}"
- else
- ''
- end
-
- if resource.instance_of?(Spree::Product)
- preview_id = ("preview_id=#{options[:preview_id]}" if options[:preview_id].present?)
-
- variant_id = ("variant_id=#{options[:variant_id]}" if options[:variant_id].present?)
-
- params = [preview_id, variant_id].compact_blank.join('&')
- params = "?#{params}" if params.present?
-
- "#{base_url + localize}/products/#{resource.slug}#{params}"
- elsif resource.is_a?(Spree::Category)
- "#{base_url + localize}/t/#{resource.permalink}"
- elsif localize.blank?
- base_url
- else
- base_url + localize
- end
- end
- end
-end
diff --git a/spree/emails/app/helpers/spree/digital_asset_helper.rb b/spree/emails/app/helpers/spree/digital_asset_helper.rb
deleted file mode 100644
index 5549bdde72..0000000000
--- a/spree/emails/app/helpers/spree/digital_asset_helper.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-module Spree
- module DigitalAssetHelper
- # Emails need an absolute link — the route helper only produces a path, and
- # the download endpoint lives on the backend rather than the storefront.
- #
- # The host is passed in rather than resolved per link: every link in one
- # email belongs to the same order, so its store is already known.
- #
- # @param digital_link [Spree::DigitalLink]
- # @param host [String] the backend's own URL
- # @return [String]
- def digital_link_download_url(digital_link, host)
- Spree::Api::DigitalLinkUrls.download_url(digital_link, host)
- end
- end
-end
diff --git a/spree/emails/app/helpers/spree/fulfillment_helper.rb b/spree/emails/app/helpers/spree/fulfillment_helper.rb
deleted file mode 100644
index 3fe9fcef5c..0000000000
--- a/spree/emails/app/helpers/spree/fulfillment_helper.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-module Spree
- module FulfillmentHelper
- def fulfillment_tracking_link_to(fulfillment:, name: nil, html_options: {})
- tracking_url = fulfillment.tracking_url.presence
- return '' unless tracking_url
-
- display_text = name || fulfillment.tracking.presence || tracking_url
-
- link_to display_text, tracking_url, html_options
- end
- end
-end
diff --git a/spree/emails/app/helpers/spree/mail_helper.rb b/spree/emails/app/helpers/spree/mail_helper.rb
deleted file mode 100644
index 1a373c7213..0000000000
--- a/spree/emails/app/helpers/spree/mail_helper.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-module Spree
- module MailHelper
- include Spree::BaseHelper
- include Spree::ImagesHelper
-
- def name_for(order)
- order.name || Spree.t('customer')
- end
- end
-end
diff --git a/spree/emails/app/mailers/spree/company_mailer.rb b/spree/emails/app/mailers/spree/company_mailer.rb
index 3eacf0893e..b4b8c03e1a 100644
--- a/spree/emails/app/mailers/spree/company_mailer.rb
+++ b/spree/emails/app/mailers/spree/company_mailer.rb
@@ -4,8 +4,6 @@ module Spree
# invitation, this is transactional, not marketing: the no-welcome-email
# rule on customer creation is untouched.
class CompanyMailer < BaseMailer
- helper Spree::MailHelper
-
# The invite carries the plaintext token; the storefront owns the
# acceptance page, so the link resolves against the store URL like other
# customer-facing links.
@@ -19,14 +17,13 @@ module Spree
return message.perform_deliveries = false unless @invitation.reload.pending?
@company = @invitation.company
- store = @company.store
+ store = @current_store = @company.store
@accept_url = append_token(invitation_base_url(store), @invitation.token)
with_store_locale(store) do
- mail(
- to: @invitation.email,
- subject: "#{store.name} #{Spree.t('company_mailer.invitation_email.subject', company: @company.name)}",
- store_url: store.storefront_url
+ mail_template(
+ { company: email_data(@company, Spree.api.company_serializer), accept_url: @accept_url },
+ to: @invitation.email, store_url: store.storefront_url
)
end
end
diff --git a/spree/emails/app/mailers/spree/customer_mailer.rb b/spree/emails/app/mailers/spree/customer_mailer.rb
index 58d55195ee..222620cca5 100644
--- a/spree/emails/app/mailers/spree/customer_mailer.rb
+++ b/spree/emails/app/mailers/spree/customer_mailer.rb
@@ -10,10 +10,9 @@ module Spree
@reset_url = append_token(base_url, reset_token)
with_store_locale(store) do
- mail(
- to: user.email,
- subject: "#{store.name} #{Spree.t('customer_mailer.password_reset_email.subject')}",
- store_url: store.storefront_url
+ mail_template(
+ { customer: email_data(user, Spree.api.customer_serializer), reset_url: @reset_url },
+ to: user.email, store_url: store.storefront_url
)
end
end
@@ -31,10 +30,9 @@ module Spree
@expires_at = data_request.expires_at
with_store_locale(@current_store) do
- mail(
- to: data_request.email,
- subject: "#{@current_store.name} #{Spree.t('customer_mailer.data_export_email.subject')}",
- store_url: @current_store.storefront_url
+ mail_template(
+ { download_url: @download_url, expires_at: @expires_at&.iso8601 },
+ to: data_request.email, store_url: @current_store.storefront_url
)
end
end
diff --git a/spree/emails/app/mailers/spree/digital_asset_mailer.rb b/spree/emails/app/mailers/spree/digital_asset_mailer.rb
index 5389429d89..f375d7a74b 100644
--- a/spree/emails/app/mailers/spree/digital_asset_mailer.rb
+++ b/spree/emails/app/mailers/spree/digital_asset_mailer.rb
@@ -1,8 +1,5 @@
module Spree
class DigitalAssetMailer < BaseMailer
- helper Spree::MailHelper
- helper Spree::DigitalAssetHelper
-
# Sent once an order's downloads are ready. Kept separate from the order
# confirmation so it can be re-sent on its own, and so a storefront that
# replaces the confirmation email does not silently lose the links.
@@ -13,17 +10,27 @@ module Spree
@digital_links = @order.digital_links.includes(digital_asset: { attachment_attachment: :blob })
return if @digital_links.empty?
- current_store = @order.store
@download_host = current_store.formatted_url
with_store_locale(current_store, @order.locale) do
- subject = order_email_subject(
- current_store,
- Spree.t('digital_asset_mailer.files_ready_email.subject'),
- @order.number,
- resend: resend
+ mail_template(
+ { order: email_data(@order, Spree::Emails::OrderSerializer),
+ downloads: downloads, resend: resend },
+ to: @order.email, store_url: current_store.storefront_url
)
- mail(to: @order.email, subject: subject, store_url: current_store.storefront_url,
- template_path: 'spree/digital_asset_mailer', template_name: 'files_ready_email')
+ end
+ end
+
+ private
+
+ # Download URLs carry each link's bearer token, so they are built here
+ # rather than serialized. They point at the backend, not the storefront.
+ def downloads
+ @digital_links.map do |digital_link|
+ {
+ filename: digital_link.filename.to_s,
+ url: Spree::Api::DigitalLinkUrls.download_url(digital_link, @download_host),
+ expires_at: digital_link.expires_at&.iso8601
+ }
end
end
end
diff --git a/spree/emails/app/mailers/spree/fulfillment_mailer.rb b/spree/emails/app/mailers/spree/fulfillment_mailer.rb
index bba8b1163b..b60d01dbe0 100644
--- a/spree/emails/app/mailers/spree/fulfillment_mailer.rb
+++ b/spree/emails/app/mailers/spree/fulfillment_mailer.rb
@@ -1,16 +1,20 @@
module Spree
class FulfillmentMailer < BaseMailer
- helper Spree::MailHelper
- helper Spree::FulfillmentHelper
-
def fulfilled_email(fulfillment, resend = false)
@fulfillment = fulfillment.respond_to?(:id) ? fulfillment : Spree::Fulfillment.find(fulfillment)
@order = @fulfillment.order
- current_store = @fulfillment.store
+ @current_store = @fulfillment.store
+
with_store_locale(current_store, @order.locale) do
- subject = order_email_subject(current_store, Spree.t('fulfillment_mailer.fulfilled_email.subject'), @order.number, resend: resend)
- mail(to: @order.email, subject: subject, store_url: current_store.storefront_url,
- template_path: 'spree/fulfillment_mailer', template_name: 'fulfilled_email')
+ mail_template(
+ {
+ fulfillment: email_data(@fulfillment, Spree::Emails::FulfillmentSerializer),
+ order: email_data(@order, Spree::Emails::OrderSerializer),
+ resend: resend
+ },
+ template: 'spree/fulfillment_mailer/fulfilled_email',
+ to: @order.email, store_url: current_store.storefront_url
+ )
end
end
end
diff --git a/spree/emails/app/mailers/spree/newsletter_mailer.rb b/spree/emails/app/mailers/spree/newsletter_mailer.rb
index 7d993e2759..a2748105d1 100644
--- a/spree/emails/app/mailers/spree/newsletter_mailer.rb
+++ b/spree/emails/app/mailers/spree/newsletter_mailer.rb
@@ -9,9 +9,8 @@ module Spree
base_url = redirect_url.presence || store.storefront_url
@confirm_email_url = append_token(base_url, @subscriber.verification_token)
with_store_locale(store) do
- mail(to: @subscriber.email, subject: Spree.t('newsletter_mailer.email_confirmation.subject'))
+ mail_template({ confirmation_url: @confirm_email_url }, to: @subscriber.email)
end
end
-
end
end
diff --git a/spree/emails/app/mailers/spree/order_group_mailer.rb b/spree/emails/app/mailers/spree/order_group_mailer.rb
index 589e127aef..720d6de4bd 100644
--- a/spree/emails/app/mailers/spree/order_group_mailer.rb
+++ b/spree/emails/app/mailers/spree/order_group_mailer.rb
@@ -12,34 +12,16 @@ module Spree
# email unchanged, and a storefront replacing one document should not have to
# inherit the other.
class OrderGroupMailer < BaseMailer
- helper Spree::MailHelper
-
# @param order_group [Spree::OrderGroup, Integer, String] record or id
# @param resend [Boolean] prefixes the subject, for an admin re-send
def confirm_email(order_group, resend = false)
@order_group = find_order_group(order_group)
- # Assigned rather than left to BaseMailer#current_store, which memoizes
- # off @order and would otherwise fall back to the default store — the
- # wrong store's name, logo and footer on a multi-store install.
- @current_store = @order_group.store
-
- with_store_locale(@current_store, @order_group.locale) do
- subject = order_email_subject(
- @current_store, Spree.t('order_group_mailer.confirm_email.subject'), @order_group.number, resend: resend
- )
- mail(to: @order_group.email, subject: subject, store_url: @current_store.storefront_url)
- end
+ deliver_order_group_email(to: @order_group.email, locale: @order_group.locale, resend: resend)
end
def store_owner_notification_email(order_group)
@order_group = find_order_group(order_group)
- @current_store = @order_group.store
-
- with_store_locale(@current_store) do
- subject = Spree.t('order_group_mailer.store_owner_notification_email.subject', store_name: @current_store.name)
- mail(to: @current_store.new_order_notifications_email, subject: subject,
- store_url: @current_store.storefront_url)
- end
+ deliver_order_group_email(to: @order_group.store.new_order_notifications_email)
end
private
@@ -47,5 +29,19 @@ module Spree
def find_order_group(order_group)
order_group.respond_to?(:id) ? order_group : Spree::OrderGroup.find(order_group)
end
+
+ def deliver_order_group_email(to:, locale: nil, resend: false)
+ # Assigned rather than left to BaseMailer#current_store, which memoizes
+ # off @order and would otherwise fall back to the default store — the
+ # wrong store's name, logo and footer on a multi-store install.
+ @current_store = @order_group.store
+
+ with_store_locale(@current_store, locale) do
+ mail_template(
+ { order_group: email_data(@order_group, Spree::Emails::OrderGroupSerializer), resend: resend },
+ to: to, store_url: @current_store.storefront_url
+ )
+ end
+ end
end
end
diff --git a/spree/emails/app/mailers/spree/order_mailer.rb b/spree/emails/app/mailers/spree/order_mailer.rb
index 3feadad025..4b3239b49c 100644
--- a/spree/emails/app/mailers/spree/order_mailer.rb
+++ b/spree/emails/app/mailers/spree/order_mailer.rb
@@ -1,42 +1,37 @@
module Spree
class OrderMailer < BaseMailer
- helper Spree::MailHelper
-
def confirm_email(order, resend = false)
@order = order.respond_to?(:id) ? order : Spree::Order.find(order)
- current_store = @order.store
- with_store_locale(current_store, @order.locale) do
- subject = order_email_subject(current_store, Spree.t('order_mailer.confirm_email.subject'), @order.number, resend: resend)
- mail(to: @order.email, subject: subject, store_url: current_store.storefront_url)
- end
+ deliver_order_email(to: @order.email, locale: @order.locale, resend: resend)
end
def store_owner_notification_email(order)
@order = order.respond_to?(:id) ? order : Spree::Order.find(order)
- current_store = @order.store
- with_store_locale(current_store) do
- subject = Spree.t('order_mailer.store_owner_notification_email.subject', store_name: current_store.name)
- mail(to: current_store.new_order_notifications_email, subject: subject, store_url: current_store.storefront_url)
- end
+ deliver_order_email(to: current_store.new_order_notifications_email)
end
def cancel_email(order, resend = false)
@order = order.respond_to?(:id) ? order : Spree::Order.find(order)
- current_store = @order.store
- with_store_locale(current_store, @order.locale) do
- subject = order_email_subject(current_store, Spree.t('order_mailer.cancel_email.subject'), @order.number, resend: resend)
- mail(to: @order.email, subject: subject, store_url: current_store.storefront_url)
- end
+ deliver_order_email(to: @order.email, locale: @order.locale, resend: resend)
end
def payment_link_email(order_id)
@order = Spree::Order.incomplete.not_canceled.find(order_id)
@current_store = @order.store
+ # Carries the order token, so it is built here and never serialized.
@checkout_payment_url = URI.join(@current_store.storefront_url, "/checkout/#{@order.token}/payment").to_s
- with_store_locale(@current_store, @order.locale) do
- mail(to: @order.email, subject: Spree.t('order_mailer.payment_link_email.subject', number: @order.number),
- store_url: @current_store.storefront_url)
+ deliver_order_email(to: @order.email, locale: @order.locale, payment_url: @checkout_payment_url)
+ end
+
+ private
+
+ def deliver_order_email(to:, locale: nil, **assigns)
+ with_store_locale(current_store, locale) do
+ mail_template(
+ { order: email_data(@order, Spree::Emails::OrderSerializer), resend: false }.merge(assigns),
+ to: to, store_url: current_store.storefront_url
+ )
end
end
end
diff --git a/spree/emails/app/mailers/spree/return_mailer.rb b/spree/emails/app/mailers/spree/return_mailer.rb
index 383df9a524..59dc53f52c 100644
--- a/spree/emails/app/mailers/spree/return_mailer.rb
+++ b/spree/emails/app/mailers/spree/return_mailer.rb
@@ -1,16 +1,21 @@
module Spree
class ReturnMailer < BaseMailer
- helper Spree::MailHelper
-
# Tells the customer their returned items were refunded. Replaces the
# reimbursement email dropped with the ReturnAuthorization chain in 6.0.
def refunded_email(return_record, resend = false)
@return = return_record.respond_to?(:id) ? return_record : Spree::Return.find(return_record)
@order = @return.order
- current_store = @return.store || Spree::Store.default
+ @current_store = @return.store || Spree::Store.default
+
with_store_locale(current_store, @order.locale) do
- subject = order_email_subject(current_store, Spree.t('return_mailer.refunded_email.subject'), @order.number, resend: resend)
- mail(to: @order.email, subject: subject, store_url: current_store.storefront_url)
+ mail_template(
+ {
+ return: email_data(@return, Spree::Emails::ReturnSerializer),
+ order: email_data(@order, Spree::Emails::OrderSerializer),
+ resend: resend
+ },
+ to: @order.email, store_url: current_store.storefront_url
+ )
end
end
end
diff --git a/spree/emails/app/mailers/spree/seller_mailer.rb b/spree/emails/app/mailers/spree/seller_mailer.rb
index a49657a19e..296c714dfb 100644
--- a/spree/emails/app/mailers/spree/seller_mailer.rb
+++ b/spree/emails/app/mailers/spree/seller_mailer.rb
@@ -6,8 +6,6 @@ module Spree
# is a lot of mail about something staff can already see in the dashboard.
# Marketplace-side notifications ride the event and webhook surface instead.
class SellerMailer < BaseMailer
- helper Spree::MailHelper
-
# @param seller [Spree::Seller, Integer]
def approved_email(seller)
@seller = load_seller(seller)
@@ -15,7 +13,7 @@ module Spree
# so a hosted dashboard, a dev Vite server and a mounted build all work.
@dashboard_url = Spree::Stores::DashboardUrl.call(store: store).presence
- deliver_to_seller('seller_mailer.approved_email.subject')
+ deliver_to_seller
end
# Carries no reason: the operator's note is an internal record, and a
@@ -23,13 +21,13 @@ module Spree
def suspended_email(seller)
@seller = load_seller(seller)
- deliver_to_seller('seller_mailer.suspended_email.subject')
+ deliver_to_seller
end
def rejected_email(seller)
@seller = load_seller(seller)
- deliver_to_seller('seller_mailer.rejected_email.subject')
+ deliver_to_seller
end
private
@@ -49,18 +47,15 @@ module Spree
(@seller.users.pluck(:email) << @seller.contact_email).compact_blank.uniq(&:downcase)
end
- # Takes the key, not the translated string: resolving the subject outside
- # the block would render it in whatever locale the job happens to run
- # under, so a seller could get an English subject over a German email.
- def deliver_to_seller(subject_key)
+ def deliver_to_seller
addresses = recipients
return message.perform_deliveries = false if addresses.empty?
+ @current_store = store
with_store_locale(store) do
- mail(
- to: addresses,
- subject: Spree.t(subject_key, store_name: store.name),
- store_url: store.storefront_url
+ mail_template(
+ { seller: email_data(@seller, Spree.api.seller_serializer), dashboard_url: @dashboard_url },
+ to: addresses, store_url: store.storefront_url
)
end
end
diff --git a/spree/emails/app/models/spree/emails/amount_line.rb b/spree/emails/app/models/spree/emails/amount_line.rb
new file mode 100644
index 0000000000..a524767d55
--- /dev/null
+++ b/spree/emails/app/models/spree/emails/amount_line.rb
@@ -0,0 +1,32 @@
+module Spree
+ module Emails
+ # One labelled amount on an email's summary: a promotion, a manual
+ # discount, a delivery rate or a fee, with rows sharing a label summed.
+ class AmountLine
+ include ActiveModel::Model
+ include ActiveModel::Attributes
+ extend Spree::DisplayMoney
+
+ attribute :label, :string
+ attribute :amount, :decimal
+ attribute :currency, :string
+
+ money_methods :amount
+
+ # Sums records sharing a label into one line each.
+ #
+ # @param records [Enumerable] the rows to sum
+ # @param currency [String]
+ # @param label [Symbol, Proc] names each row
+ # @param amount [Symbol] the method giving each row's amount
+ # @param keep_zero [Boolean] whether a line coming to zero is kept
+ # @return [Array<Spree::Emails::AmountLine>]
+ def self.group(records, currency:, label: :label, amount: :amount, keep_zero: false)
+ records.to_a.group_by(&label).filter_map do |name, rows|
+ sum = rows.sum { |row| row.public_send(amount).to_d }
+ new(label: name, amount: sum, currency: currency) if keep_zero || !sum.zero?
+ end
+ end
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/amount_line_serializer.rb b/spree/emails/app/serializers/spree/emails/amount_line_serializer.rb
new file mode 100644
index 0000000000..743a5507f7
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/amount_line_serializer.rb
@@ -0,0 +1,17 @@
+module Spree
+ module Emails
+ class AmountLineSerializer
+ include Alba::Resource
+
+ attributes :label
+
+ attribute :display_amount do |line|
+ line.display_amount.to_s
+ end
+
+ attribute :amount do |line|
+ line.amount.to_s
+ end
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/fulfillment_group_serializer.rb b/spree/emails/app/serializers/spree/emails/fulfillment_group_serializer.rb
new file mode 100644
index 0000000000..69b4ffd8b9
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/fulfillment_group_serializer.rb
@@ -0,0 +1,22 @@
+module Spree
+ module Emails
+ # One real parcel of a purchase: what it carries, who sold it and what it
+ # cost to deliver.
+ class FulfillmentGroupSerializer
+ include Alba::Resource
+
+ attributes :name
+
+ attribute :display_cost do |group|
+ group.display_cost.to_s
+ end
+
+ attribute :seller_names do |group|
+ group.sellers.map(&:name)
+ end
+
+ many :manifest, key: :items, source: proc { manifest.select(&:line_item) },
+ resource: Spree::Emails::ParcelItemSerializer
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/fulfillment_serializer.rb b/spree/emails/app/serializers/spree/emails/fulfillment_serializer.rb
new file mode 100644
index 0000000000..9140e0ed10
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/fulfillment_serializer.rb
@@ -0,0 +1,12 @@
+module Spree
+ module Emails
+ class FulfillmentSerializer < Spree::Api::V3::FulfillmentSerializer
+ attribute :delivery_method_name do |fulfillment|
+ fulfillment.delivery_method&.name
+ end
+
+ many :manifest, key: :manifest_items, source: proc { manifest.select(&:line_item) },
+ resource: Spree::Emails::ParcelItemSerializer
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/line_item_serializer.rb b/spree/emails/app/serializers/spree/emails/line_item_serializer.rb
new file mode 100644
index 0000000000..5a81a2fa7d
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/line_item_serializer.rb
@@ -0,0 +1,17 @@
+module Spree
+ module Emails
+ class LineItemSerializer < Spree::Api::V3::LineItemSerializer
+ include Spree::Emails::PurchasedItemAttributes
+
+ attributes :sku
+
+ # Price times quantity, before discounts — what the line cost.
+ attribute :display_amount do |line_item|
+ line_item.display_amount.to_s
+ end
+
+ # The full-size image; emails show the thumbnail in `image_url`.
+ attributes :thumbnail_url, if: proc { false }
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/order_group_serializer.rb b/spree/emails/app/serializers/spree/emails/order_group_serializer.rb
new file mode 100644
index 0000000000..dc84c7bc4b
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/order_group_serializer.rb
@@ -0,0 +1,55 @@
+module Spree
+ module Emails
+ # A purchase that divided into several orders, as its confirmation reads
+ # it: every item, the parcels it ships in, and one set of totals.
+ class OrderGroupSerializer < Spree::Api::V3::OrderGroupSerializer
+ include Spree::Emails::PurchaseSummaryAttributes
+
+ attributes :po_number
+
+ attribute :order_count do |group|
+ group.orders.size
+ end
+
+ attribute :display_delivery_total do |group|
+ group.display_delivery_total.to_s
+ end
+
+ attribute :delivery_total do |group|
+ group.delivery_total.to_s
+ end
+
+ attribute :additional_tax_total do |group|
+ group.additional_tax_total.to_s
+ end
+
+ attribute :display_additional_tax_total do |group|
+ group.display_additional_tax_total.to_s
+ end
+
+ attribute :gift_card_total do |group|
+ group.gift_card_total.to_s
+ end
+
+ attribute :display_gift_card_total do |group|
+ group.display_gift_card_total.to_s
+ end
+
+ # Every child order in full is what the webhook payload carries; the
+ # email reads the purchase-wide fields above instead.
+ many :orders, resource: proc { Spree.api.order_serializer }, if: proc { false }
+
+ many :fulfillment_groups, resource: Spree::Emails::FulfillmentGroupSerializer
+
+ # What no parcel carries — a download, an emailed gift card.
+ many :unfulfilled_items,
+ source: proc { unfulfilled_line_items },
+ resource: Spree::Emails::LineItemSerializer
+
+ # One delivery row for the whole purchase; the parcels break it down.
+ many :delivery_lines,
+ source: proc { delivery_total.zero? ? [] : [Spree::Emails::AmountLine.new(amount: delivery_total, currency: currency)] },
+ resource: Spree::Emails::AmountLineSerializer
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/order_serializer.rb b/spree/emails/app/serializers/spree/emails/order_serializer.rb
new file mode 100644
index 0000000000..57058988f6
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/order_serializer.rb
@@ -0,0 +1,18 @@
+module Spree
+ module Emails
+ # An order as its emails read it: the Store API order plus what only an
+ # email shows — who to greet, the summary rows and line thumbnails.
+ class OrderSerializer < Spree::Api::V3::OrderSerializer
+ include Spree::Emails::PurchaseSummaryAttributes
+
+ # One row per delivery rate, at its cost before discounts, so the rows
+ # add up to the total once a free-delivery promotion is listed.
+ many :delivery_lines,
+ source: proc {
+ Spree::Emails::AmountLine.group(fulfillments, currency: currency, amount: :cost, keep_zero: true,
+ label: ->(fulfillment) { fulfillment.selected_delivery_rate&.name })
+ },
+ resource: Spree::Emails::AmountLineSerializer
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/parcel_item_serializer.rb b/spree/emails/app/serializers/spree/emails/parcel_item_serializer.rb
new file mode 100644
index 0000000000..cdd7076241
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/parcel_item_serializer.rb
@@ -0,0 +1,36 @@
+module Spree
+ module Emails
+ # One line as it travels in one parcel. A line packed from two warehouses
+ # rides in two parcels, so the quantity and amount are the parcel's share
+ # rather than the whole line's.
+ class ParcelItemSerializer < Spree::Emails::BaseSerializer
+ include Spree::Emails::PurchasedItemAttributes
+
+ attribute :id do |item|
+ item.line_item.prefixed_id
+ end
+
+ attribute :name do |item|
+ item.line_item.name
+ end
+
+ attributes :quantity
+
+ attribute :sku do |item|
+ item.line_item.sku
+ end
+
+ attribute :options_text do |item|
+ item.line_item.options_text
+ end
+
+ attribute :display_price do |item|
+ item.line_item.display_price.to_s
+ end
+
+ attribute :display_amount do |item|
+ Spree::Money.new(item.line_item.price * item.quantity, currency: item.line_item.currency).to_s
+ end
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/purchase_summary_attributes.rb b/spree/emails/app/serializers/spree/emails/purchase_summary_attributes.rb
new file mode 100644
index 0000000000..618c5ebcc2
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/purchase_summary_attributes.rb
@@ -0,0 +1,37 @@
+module Spree
+ module Emails
+ # What an email shows for a whole purchase — who to greet, the items and
+ # the summary rows — for both an order and a multi-seller purchase. The
+ # `spree/shared/purchase_totals` partial reads these names from either.
+ module PurchaseSummaryAttributes
+ extend ActiveSupport::Concern
+
+ included do
+ attribute :customer_name do |purchase|
+ purchase.name.presence || Spree.t(:customer)
+ end
+
+ attribute :display_total_minus_store_credits do |purchase|
+ purchase.display_total_minus_store_credits.to_s
+ end
+
+ many :line_items, key: :items, resource: Spree::Emails::LineItemSerializer
+
+ many :promotion_discounts,
+ source: proc { Spree::Emails::AmountLine.group(discounts.promotion, currency: currency) },
+ resource: Spree::Emails::AmountLineSerializer
+
+ many :manual_discounts,
+ source: proc { Spree::Emails::AmountLine.group(discounts.manual, currency: currency) },
+ resource: Spree::Emails::AmountLineSerializer
+
+ # A multi-seller checkout apportions an order-level fee into one row
+ # per child, all under one label; summed back, it is the one charge the
+ # customer saw.
+ many :fee_lines,
+ source: proc { Spree::Emails::AmountLine.group(fees, currency: currency) },
+ resource: Spree::Emails::AmountLineSerializer
+ end
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/purchased_item_attributes.rb b/spree/emails/app/serializers/spree/emails/purchased_item_attributes.rb
new file mode 100644
index 0000000000..70bbe359c7
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/purchased_item_attributes.rb
@@ -0,0 +1,28 @@
+module Spree
+ module Emails
+ # What an email shows for a purchased line besides its Store API fields: a
+ # link to the product on the storefront and a thumbnail. Shared by the line
+ # item and parcel item serializers.
+ module PurchasedItemAttributes
+ extend ActiveSupport::Concern
+ include Spree::ImagesHelper
+
+ included do
+ attribute :url do |item|
+ product = purchased_line_item(item).product
+ "#{params[:storefront_url]}/products/#{product.slug}" if product
+ end
+
+ attribute :image_url do |item|
+ spree_image_url(purchased_line_item(item).thumbnail, variant: :small)
+ end
+ end
+
+ private
+
+ def purchased_line_item(item)
+ item.is_a?(Spree::LineItem) ? item : item.line_item
+ end
+ end
+ end
+end
diff --git a/spree/emails/app/serializers/spree/emails/return_serializer.rb b/spree/emails/app/serializers/spree/emails/return_serializer.rb
new file mode 100644
index 0000000000..be7c30f288
--- /dev/null
+++ b/spree/emails/app/serializers/spree/emails/return_serializer.rb
@@ -0,0 +1,15 @@
+module Spree
+ module Emails
+ class ReturnSerializer < Spree::Api::V3::ReturnSerializer
+ # What was actually paid back — not the Store API's refund_total, which
+ # is the figure the return was expected to refund.
+ attribute :display_refunded_total do |return_record|
+ return_record.display_refunded_total.to_s
+ end
+
+ many :returned_items,
+ source: proc { return_line_items.filter_map(&:line_item).uniq },
+ resource: Spree::Emails::LineItemSerializer
+ end
+ end
+end
diff --git a/spree/emails/app/views/spree/company_mailer/invitation_email.html.erb b/spree/emails/app/views/spree/company_mailer/invitation_email.html.erb
deleted file mode 100644
index 09d85f7e52..0000000000
--- a/spree/emails/app/views/spree/company_mailer/invitation_email.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('company_mailer.invitation_email.title', company: @company.name) %></h1>
- <p class="greeting"><%= Spree.t('company_mailer.invitation_email.greeting') %></p>
- <p><%= Spree.t('company_mailer.invitation_email.instructions', company: @company.name, store: current_store.name) %></p>
- <%= render 'spree/shared/mailer_button', url: @accept_url, label: Spree.t('company_mailer.invitation_email.action') %>
- <p class="sub"><%= Spree.t('company_mailer.invitation_email.expiry_notice') %></p>
- <p class="sub"><%= Spree.t('company_mailer.invitation_email.ignore_notice') %></p>
-<% end %>
diff --git a/spree/emails/app/views/spree/company_mailer/invitation_email.liquid b/spree/emails/app/views/spree/company_mailer/invitation_email.liquid
new file mode 100644
index 0000000000..a23a5e6429
--- /dev/null
+++ b/spree/emails/app/views/spree/company_mailer/invitation_email.liquid
@@ -0,0 +1,13 @@
+---
+subject: "{{ store.name }} {{ 'company_mailer.invitation_email.subject' | t: company: company.name }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'company_mailer.invitation_email.title' | t: company: company.name }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'company_mailer.invitation_email.greeting' | t }}</mj-text>
+ <mj-text mj-class="lead">{{ 'company_mailer.invitation_email.instructions' | t: company: company.name, store: store.name }}</mj-text>
+ <mj-button href="{{ accept_url }}">{{ 'company_mailer.invitation_email.action' | t }}</mj-button>
+ <mj-text mj-class="note">{{ 'company_mailer.invitation_email.expiry_notice' | t }}</mj-text>
+ <mj-text mj-class="note" padding="16px 0 0">{{ 'company_mailer.invitation_email.ignore_notice' | t }}</mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/company_mailer/invitation_email.text.erb b/spree/emails/app/views/spree/company_mailer/invitation_email.text.erb
deleted file mode 100644
index e8a062db66..0000000000
--- a/spree/emails/app/views/spree/company_mailer/invitation_email.text.erb
+++ /dev/null
@@ -1,11 +0,0 @@
-<%= Spree.t('company_mailer.invitation_email.greeting') %>
-
-<%= Spree.t('company_mailer.invitation_email.instructions', company: @company.name, store: current_store.name) %>
-
-<%= Spree.t('company_mailer.invitation_email.action') %>: <%= @accept_url %>
-
-<%= Spree.t('company_mailer.invitation_email.expiry_notice') %>
-
-<%= Spree.t('company_mailer.invitation_email.ignore_notice') %>
-
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/customer_mailer/data_export_email.html.erb b/spree/emails/app/views/spree/customer_mailer/data_export_email.html.erb
deleted file mode 100644
index ec2aff91c4..0000000000
--- a/spree/emails/app/views/spree/customer_mailer/data_export_email.html.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('customer_mailer.data_export_email.action') %></h1>
- <p class="greeting"><%= Spree.t('customer_mailer.data_export_email.greeting') %></p>
- <p><%= Spree.t('customer_mailer.data_export_email.instructions') %></p>
- <% if @download_url %>
- <%= render 'spree/shared/mailer_button', url: @download_url, label: Spree.t('customer_mailer.data_export_email.action') %>
- <% end %>
- <% if @expires_at %>
- <p class="sub"><%= Spree.t('customer_mailer.data_export_email.expiry_notice', date: I18n.l(@expires_at.to_date, format: :long)) %></p>
- <% end %>
- <p class="sub"><%= Spree.t('customer_mailer.data_export_email.ignore_notice') %></p>
-<% end %>
diff --git a/spree/emails/app/views/spree/customer_mailer/data_export_email.liquid b/spree/emails/app/views/spree/customer_mailer/data_export_email.liquid
new file mode 100644
index 0000000000..078d118bdc
--- /dev/null
+++ b/spree/emails/app/views/spree/customer_mailer/data_export_email.liquid
@@ -0,0 +1,18 @@
+---
+subject: "{{ store.name }} {{ 'customer_mailer.data_export_email.subject' | t }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'customer_mailer.data_export_email.action' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'customer_mailer.data_export_email.greeting' | t }}</mj-text>
+ <mj-text mj-class="lead">{{ 'customer_mailer.data_export_email.instructions' | t }}</mj-text>
+ {% if download_url %}
+ <mj-button href="{{ download_url }}">{{ 'customer_mailer.data_export_email.action' | t }}</mj-button>
+ {% endif %}
+ {% if expires_at %}
+ {% assign expires_on = expires_at | date: 'long' %}
+ <mj-text mj-class="note">{{ 'customer_mailer.data_export_email.expiry_notice' | t: date: expires_on }}</mj-text>
+ {% endif %}
+ <mj-text mj-class="note" padding="16px 0 0">{{ 'customer_mailer.data_export_email.ignore_notice' | t }}</mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/customer_mailer/data_export_email.text.erb b/spree/emails/app/views/spree/customer_mailer/data_export_email.text.erb
deleted file mode 100644
index 0b6b58e69d..0000000000
--- a/spree/emails/app/views/spree/customer_mailer/data_export_email.text.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<%= Spree.t('customer_mailer.data_export_email.greeting') %>
-
-<%= Spree.t('customer_mailer.data_export_email.instructions') %>
-
-<% if @download_url %><%= @download_url %><% end %>
-
-<% if @expires_at %><%= Spree.t('customer_mailer.data_export_email.expiry_notice', date: I18n.l(@expires_at.to_date, format: :long)) %><% end %>
-
-<%= Spree.t('customer_mailer.data_export_email.ignore_notice') %>
diff --git a/spree/emails/app/views/spree/customer_mailer/password_reset_email.html.erb b/spree/emails/app/views/spree/customer_mailer/password_reset_email.html.erb
deleted file mode 100644
index d97e3bd5b1..0000000000
--- a/spree/emails/app/views/spree/customer_mailer/password_reset_email.html.erb
+++ /dev/null
@@ -1,10 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('customer_mailer.password_reset_email.action') %></h1>
- <p class="greeting"><%= Spree.t('customer_mailer.password_reset_email.greeting', name: @user.first_name.presence || @user.email) %></p>
- <p><%= Spree.t('customer_mailer.password_reset_email.instructions') %></p>
- <% if @reset_url %>
- <%= render 'spree/shared/mailer_button', url: @reset_url, label: Spree.t('customer_mailer.password_reset_email.action') %>
- <% end %>
- <p class="sub"><%= Spree.t('customer_mailer.password_reset_email.expiry_notice') %></p>
- <p class="sub"><%= Spree.t('customer_mailer.password_reset_email.ignore_notice') %></p>
-<% end %>
diff --git a/spree/emails/app/views/spree/customer_mailer/password_reset_email.liquid b/spree/emails/app/views/spree/customer_mailer/password_reset_email.liquid
new file mode 100644
index 0000000000..ac94b7bb08
--- /dev/null
+++ b/spree/emails/app/views/spree/customer_mailer/password_reset_email.liquid
@@ -0,0 +1,14 @@
+---
+subject: "{{ store.name }} {{ 'customer_mailer.password_reset_email.subject' | t }}"
+---
+{% assign name = customer.first_name | default: customer.email %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'customer_mailer.password_reset_email.action' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'customer_mailer.password_reset_email.greeting' | t: name: name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'customer_mailer.password_reset_email.instructions' | t }}</mj-text>
+ <mj-button href="{{ reset_url }}">{{ 'customer_mailer.password_reset_email.action' | t }}</mj-button>
+ <mj-text mj-class="note">{{ 'customer_mailer.password_reset_email.expiry_notice' | t }}</mj-text>
+ <mj-text mj-class="note" padding="16px 0 0">{{ 'customer_mailer.password_reset_email.ignore_notice' | t }}</mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/customer_mailer/password_reset_email.text.erb b/spree/emails/app/views/spree/customer_mailer/password_reset_email.text.erb
deleted file mode 100644
index 990c14dfd1..0000000000
--- a/spree/emails/app/views/spree/customer_mailer/password_reset_email.text.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-<%= Spree.t('customer_mailer.password_reset_email.greeting', name: @user.first_name.presence || @user.email) %>
-
-<%= Spree.t('customer_mailer.password_reset_email.instructions') %>
-
-<% if @reset_url %>
-<%= Spree.t('customer_mailer.password_reset_email.action') %>: <%= @reset_url %>
-<% end %>
-
-<%= Spree.t('customer_mailer.password_reset_email.expiry_notice') %>
-
-<%= Spree.t('customer_mailer.password_reset_email.ignore_notice') %>
-
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/digital_asset_mailer/files_ready_email.html.erb b/spree/emails/app/views/spree/digital_asset_mailer/files_ready_email.html.erb
deleted file mode 100644
index 9b8f3f6fde..0000000000
--- a/spree/emails/app/views/spree/digital_asset_mailer/files_ready_email.html.erb
+++ /dev/null
@@ -1,20 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('digital_asset_mailer.files_ready_email.subject') %></h1>
- <p class="greeting"><%= Spree.t('digital_asset_mailer.files_ready_email.dear_customer', name: name_for(@order)) %></p>
- <p><%= Spree.t('digital_asset_mailer.files_ready_email.instructions', number: @order.number) %></p>
-<% end %>
-
-<table width="100%" cellpadding="0" cellspacing="0" border="0">
- <% @digital_links.each do |digital_link| %>
- <tr>
- <td style="padding: 8px 0;">
- <a href="<%= digital_link_download_url(digital_link, @download_host) %>"><%= digital_link.filename %></a>
- <% if digital_link.expires_at %>
- <div style="font-size: 12px; color: #666;">
- <%= Spree.t('digital_asset_mailer.files_ready_email.available_until', date: l(digital_link.expires_at.to_date, format: :long)) %>
- </div>
- <% end %>
- </td>
- </tr>
- <% end %>
-</table>
diff --git a/spree/emails/app/views/spree/digital_asset_mailer/files_ready_email.liquid b/spree/emails/app/views/spree/digital_asset_mailer/files_ready_email.liquid
new file mode 100644
index 0000000000..c8b1be9a38
--- /dev/null
+++ b/spree/emails/app/views/spree/digital_asset_mailer/files_ready_email.liquid
@@ -0,0 +1,23 @@
+---
+subject: "{% if resend %}[{{ 'resend' | t | upcase }}] {% endif %}{{ store.name }} {{ 'digital_asset_mailer.files_ready_email.subject' | t }} #{{ order.number }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'digital_asset_mailer.files_ready_email.subject' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'digital_asset_mailer.files_ready_email.dear_customer' | t: name: order.customer_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'digital_asset_mailer.files_ready_email.instructions' | t: number: order.number }}</mj-text>
+ </mj-column>
+</mj-section>
+<mj-section padding="32px 0 0">
+ <mj-column>
+ {% for download in downloads %}
+ <mj-text mj-class="body" padding="8px 0 0">
+ <a href="{{ download.url }}">{{ download.filename }}</a>
+ {% if download.expires_at %}
+ {% assign expires_on = download.expires_at | date: 'long' %}
+ <br /><span style="font-size: 12px;">{{ 'digital_asset_mailer.files_ready_email.available_until' | t: date: expires_on }}</span>
+ {% endif %}
+ </mj-text>
+ {% endfor %}
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/digital_asset_mailer/files_ready_email.text.erb b/spree/emails/app/views/spree/digital_asset_mailer/files_ready_email.text.erb
deleted file mode 100644
index 9e14d43b20..0000000000
--- a/spree/emails/app/views/spree/digital_asset_mailer/files_ready_email.text.erb
+++ /dev/null
@@ -1,10 +0,0 @@
-<%= Spree.t('digital_asset_mailer.files_ready_email.dear_customer', name: name_for(@order)) %>
-
-<%= Spree.t('digital_asset_mailer.files_ready_email.instructions', number: @order.number) %>
-
-<% @digital_links.each do |digital_link| %>
-<%= digital_link.filename %>
-<%= digital_link_download_url(digital_link, @download_host) %>
-<% if digital_link.expires_at %><%= Spree.t('digital_asset_mailer.files_ready_email.available_until', date: l(digital_link.expires_at.to_date, format: :long)) %>
-<% end %>
-<% end %>
diff --git a/spree/emails/app/views/spree/fulfillment_mailer/fulfilled_email.html.erb b/spree/emails/app/views/spree/fulfillment_mailer/fulfilled_email.html.erb
deleted file mode 100644
index 245ddf4dbb..0000000000
--- a/spree/emails/app/views/spree/fulfillment_mailer/fulfilled_email.html.erb
+++ /dev/null
@@ -1,22 +0,0 @@
-<%= render 'spree/shared/purchased_items_styles' %>
-
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('fulfillment_mailer.fulfilled_email.subject') %></h1>
- <p class="greeting"><%= Spree.t('fulfillment_mailer.fulfilled_email.dear_customer', name: name_for(@fulfillment.order)) %></p>
- <p><%= Spree.t('fulfillment_mailer.fulfilled_email.instructions', number: @fulfillment.order.number) %></p>
- <% if @fulfillment.delivery_method %>
- <p><%= Spree.t('fulfillment_mailer.fulfilled_email.delivery_method', delivery_method: @fulfillment.delivery_method.name) %></p>
- <% end %>
- <% if @fulfillment.tracking %>
- <p><%= Spree.t('fulfillment_mailer.fulfilled_email.track_information', tracking: @fulfillment.tracking) %></p>
- <% end %>
- <% if @fulfillment.tracking_url %>
- <p><%= Spree.t('fulfillment_mailer.fulfilled_email.track_link', url: fulfillment_tracking_link_to(fulfillment: @fulfillment)).html_safe %></p>
- <% end %>
-<% end %>
-
-<%= render 'spree/shared/order_summary_section',
- heading: Spree.t('fulfillment_mailer.fulfilled_email.fulfillment_summary'),
- line_items: @fulfillment.manifest.map(&:line_item),
- order: @fulfillment.order,
- totals: false %>
diff --git a/spree/emails/app/views/spree/fulfillment_mailer/fulfilled_email.liquid b/spree/emails/app/views/spree/fulfillment_mailer/fulfilled_email.liquid
new file mode 100644
index 0000000000..fbc754fa43
--- /dev/null
+++ b/spree/emails/app/views/spree/fulfillment_mailer/fulfilled_email.liquid
@@ -0,0 +1,21 @@
+---
+subject: "{% if resend %}[{{ 'resend' | t | upcase }}] {% endif %}{{ store.name }} {{ 'fulfillment_mailer.fulfilled_email.subject' | t }} #{{ order.number }}"
+---
+{% assign heading = 'fulfillment_mailer.fulfilled_email.fulfillment_summary' | t %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'fulfillment_mailer.fulfilled_email.subject' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'fulfillment_mailer.fulfilled_email.dear_customer' | t: name: order.customer_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'fulfillment_mailer.fulfilled_email.instructions' | t: number: order.number }}</mj-text>
+ {% if fulfillment.delivery_method_name != blank %}
+ <mj-text mj-class="lead">{{ 'fulfillment_mailer.fulfilled_email.delivery_method' | t: delivery_method: fulfillment.delivery_method_name }}</mj-text>
+ {% endif %}
+ {% if fulfillment.tracking != blank %}
+ <mj-text mj-class="lead">{{ 'fulfillment_mailer.fulfilled_email.track_information' | t: tracking: fulfillment.tracking }}</mj-text>
+ {% endif %}
+ {% if fulfillment.tracking_url != blank %}
+ <mj-button href="{{ fulfillment.tracking_url }}">{{ fulfillment.tracking | default: fulfillment.tracking_url }}</mj-button>
+ {% endif %}
+ </mj-column>
+</mj-section>
+{% render 'spree/shared/order_summary', heading: heading, purchase: order, items: fulfillment.manifest_items, totals: false %}
diff --git a/spree/emails/app/views/spree/fulfillment_mailer/fulfilled_email.text.erb b/spree/emails/app/views/spree/fulfillment_mailer/fulfilled_email.text.erb
deleted file mode 100644
index 121b946b6c..0000000000
--- a/spree/emails/app/views/spree/fulfillment_mailer/fulfilled_email.text.erb
+++ /dev/null
@@ -1,18 +0,0 @@
-<%= Spree.t('fulfillment_mailer.fulfilled_email.dear_customer', name: name_for(@fulfillment.order)) %>
-
-<%= Spree.t('fulfillment_mailer.fulfilled_email.instructions', number: @fulfillment.order.number) %>
-
-============================================================
-<%= Spree.t('fulfillment_mailer.fulfilled_email.fulfillment_summary') %>
-============================================================
-<%= render 'spree/shared/po_number', order: @fulfillment.order %>
-<% @fulfillment.manifest.each do |item| %>
- <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text %>
-<% end %>
-============================================================
-
-<%= Spree.t('fulfillment_mailer.fulfilled_email.track_information', tracking: @fulfillment.tracking) if @fulfillment.tracking %>
-<%= Spree.t('fulfillment_mailer.fulfilled_email.track_link', url: @fulfillment.tracking_url) if @fulfillment.tracking_url %>
-
-<%= Spree.t('fulfillment_mailer.fulfilled_email.thanks') %>
-<%= Spree.t('fulfillment_mailer.fulfilled_email.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.html.erb b/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.html.erb
deleted file mode 100644
index b8317f6c54..0000000000
--- a/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.html.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('newsletter_mailer.email_confirmation.subject') %></h1>
- <p class="greeting"><%= Spree.t('newsletter_mailer.email_confirmation.dear_customer') %></p>
- <p><%= Spree.t('newsletter_mailer.email_confirmation.instructions') %></p>
- <%= render 'spree/shared/mailer_button', url: @confirm_email_url, label: Spree.t('newsletter_mailer.email_confirmation.verify_email_address_link') %>
- <p class="sub">
- <%= Spree.t('newsletter_mailer.email_confirmation.message_copy_link') %>
- <br>
- <%= link_to @confirm_email_url, @confirm_email_url %>
- </p>
- <p class="sub"><%= Spree.t('newsletter_mailer.email_confirmation.ignore_disclaimer') %></p>
-<% end %>
diff --git a/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.liquid b/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.liquid
new file mode 100644
index 0000000000..880ecb78c4
--- /dev/null
+++ b/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.liquid
@@ -0,0 +1,13 @@
+---
+subject: "{{ 'newsletter_mailer.email_confirmation.subject' | t }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'newsletter_mailer.email_confirmation.subject' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'newsletter_mailer.email_confirmation.dear_customer' | t }}</mj-text>
+ <mj-text mj-class="lead">{{ 'newsletter_mailer.email_confirmation.instructions' | t }}</mj-text>
+ <mj-button href="{{ confirmation_url }}">{{ 'newsletter_mailer.email_confirmation.verify_email_address_link' | t }}</mj-button>
+ <mj-text mj-class="note">{{ 'newsletter_mailer.email_confirmation.message_copy_link' | t }}<br /><a href="{{ confirmation_url }}">{{ confirmation_url }}</a></mj-text>
+ <mj-text mj-class="note" padding="16px 0 0">{{ 'newsletter_mailer.email_confirmation.ignore_disclaimer' | t }}</mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.text.erb b/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.text.erb
deleted file mode 100644
index ac62cbb570..0000000000
--- a/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.text.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<%= Spree.t('newsletter_mailer.email_confirmation.dear_customer') %>
-<%= Spree.t('newsletter_mailer.email_confirmation.instructions') %>
-
-<%= @confirm_email_url %>
-
-<%= Spree.t('newsletter_mailer.email_confirmation.ignore_disclaimer') %>
-============================================================
-<%= Spree.t('newsletter_mailer.email_confirmation.thanks') %>
-<%= Spree.t('newsletter_mailer.email_confirmation.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/order_group_mailer/confirm_email.html.erb b/spree/emails/app/views/spree/order_group_mailer/confirm_email.html.erb
deleted file mode 100644
index 4836eef8db..0000000000
--- a/spree/emails/app/views/spree/order_group_mailer/confirm_email.html.erb
+++ /dev/null
@@ -1,38 +0,0 @@
-<%= render 'spree/shared/purchased_items_styles' %>
-
-<% fulfillment_groups = @order_group.fulfillment_groups %>
-<% unfulfilled_line_items = @order_group.unfulfilled_line_items(fulfillment_groups) %>
-
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('order_group_mailer.confirm_email.subject') %></h1>
- <p class="greeting"><%= Spree.t('order_group_mailer.confirm_email.dear_customer', name: name_for(@order_group)) %></p>
- <p><%= Spree.t('order_group_mailer.confirm_email.instructions', number: @order_group.number) %></p>
- <%# What the customer most needs and least expects: this arrives in more
- than one delivery. Counted from the parcels, never from the orders the
- checkout divided into — several sellers shipping out of one warehouse
- send one box. %>
- <% if fulfillment_groups.many? %>
- <p><%= Spree.t('order_group_mailer.confirm_email.arriving_separately', count: fulfillment_groups.size) %></p>
- <% end %>
-<% end %>
-
-<% if @order_group.po_number.present? %>
- <p class="f-fallback"><%= Spree.t('order_mailer.po_number', number: @order_group.po_number) %></p>
-<% end %>
-
-<% fulfillment_groups.each_with_index do |fulfillment_group, index| %>
- <%= render 'spree/shared/fulfillment_group_section',
- fulfillment_group: fulfillment_group,
- position: index + 1,
- count: fulfillment_groups.size %>
-<% end %>
-
-<% if unfulfilled_line_items.any? %>
- <%= render 'spree/shared/order_summary_section',
- heading: Spree.t('order_group_mailer.nothing_to_ship'),
- line_items: unfulfilled_line_items,
- order: @order_group,
- totals: false %>
-<% end %>
-
-<%= render 'spree/shared/purchase_totals', order_group: @order_group %>
diff --git a/spree/emails/app/views/spree/order_group_mailer/confirm_email.liquid b/spree/emails/app/views/spree/order_group_mailer/confirm_email.liquid
new file mode 100644
index 0000000000..91dbb33239
--- /dev/null
+++ b/spree/emails/app/views/spree/order_group_mailer/confirm_email.liquid
@@ -0,0 +1,35 @@
+---
+subject: "{% if resend %}[{{ 'resend' | t | upcase }}] {% endif %}{{ store.name }} {{ 'order_group_mailer.confirm_email.subject' | t }} #{{ order_group.number }}"
+---
+{% assign parcel_count = order_group.fulfillment_groups.size %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'order_group_mailer.confirm_email.subject' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'order_group_mailer.confirm_email.dear_customer' | t: name: order_group.customer_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'order_group_mailer.confirm_email.instructions' | t: number: order_group.number }}</mj-text>
+ {%- comment -%}Counted from the parcels, never from the orders the checkout divided into: several sellers shipping out of one warehouse send one box.{%- endcomment -%}
+ {% if parcel_count > 1 %}
+ <mj-text mj-class="lead">{{ 'order_group_mailer.confirm_email.arriving_separately' | t: count: parcel_count }}</mj-text>
+ {% endif %}
+ </mj-column>
+</mj-section>
+{% if order_group.po_number != blank %}
+<mj-section padding="48px 0 0">
+ <mj-column>
+ <mj-text mj-class="body" padding="0">{{ 'order_mailer.po_number' | t: number: order_group.po_number }}</mj-text>
+ </mj-column>
+</mj-section>
+{% endif %}
+{% for group in order_group.fulfillment_groups %}
+ {% render 'spree/shared/fulfillment_group', group: group, position: forloop.index, count: parcel_count %}
+{% endfor %}
+{% if order_group.unfulfilled_items.size > 0 %}
+ {% assign heading = 'order_group_mailer.nothing_to_ship' | t %}
+ {% render 'spree/shared/order_summary', heading: heading, purchase: order_group, items: order_group.unfulfilled_items, totals: false %}
+{% endif %}
+<mj-section padding="48px 0 0">
+ <mj-column>
+ <mj-text mj-class="section-heading" padding="0">{{ 'order_summary' | t }}</mj-text>
+ {% render 'spree/shared/purchase_totals', purchase: order_group %}
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/order_group_mailer/confirm_email.text.erb b/spree/emails/app/views/spree/order_group_mailer/confirm_email.text.erb
deleted file mode 100644
index e3f2fd091e..0000000000
--- a/spree/emails/app/views/spree/order_group_mailer/confirm_email.text.erb
+++ /dev/null
@@ -1,26 +0,0 @@
-<% fulfillment_groups = @order_group.fulfillment_groups %>
-<% unfulfilled_line_items = @order_group.unfulfilled_line_items(fulfillment_groups) %>
-<%= Spree.t('order_group_mailer.confirm_email.dear_customer', name: name_for(@order_group)) %>
-
-<%= Spree.t('order_group_mailer.confirm_email.instructions', number: @order_group.number) %>
-<% if fulfillment_groups.many? %>
-<%= Spree.t('order_group_mailer.confirm_email.arriving_separately', count: fulfillment_groups.size) %>
-<% end %>
-<%= render 'spree/shared/po_number', order: @order_group %>
-<% fulfillment_groups.each_with_index do |fulfillment_group, index| %>
-============================================================
-<%= render 'spree/shared/fulfillment_group_section',
- fulfillment_group: fulfillment_group,
- position: index + 1,
- count: fulfillment_groups.size %>
-<% end %>
-<% if unfulfilled_line_items.any? %>
-============================================================
-<%= Spree.t('order_group_mailer.nothing_to_ship') %>
-<% unfulfilled_line_items.each do |item| %>
- <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text -%> (<%= item.quantity %>) <%= Spree.t('at_symbol') %> <%= item.single_money %> = <%= item.display_amount %>
-<% end %>
-<% end %>
-<%= render 'spree/shared/purchase_totals', order_group: @order_group %>
-<%= Spree.t('order_group_mailer.confirm_email.thanks') %>
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.html.erb b/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.html.erb
deleted file mode 100644
index 0860fa5ae0..0000000000
--- a/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.html.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-<%= render 'spree/shared/purchased_items_styles' %>
-
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('order_group_mailer.store_owner_notification_email.heading') %></h1>
- <p><%= Spree.t('order_group_mailer.store_owner_notification_email.instructions', count: @order_group.orders.size) %></p>
-<% end %>
-
-<%= render 'spree/shared/order_summary_section',
- heading: Spree.t('order_group_mailer.store_owner_notification_email.purchase_summary', number: @order_group.number),
- line_items: @order_group.line_items,
- order: @order_group,
- totals: false %>
-
-<%= render 'spree/shared/purchase_totals', order_group: @order_group %>
diff --git a/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.liquid b/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.liquid
new file mode 100644
index 0000000000..5be17964c9
--- /dev/null
+++ b/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.liquid
@@ -0,0 +1,11 @@
+---
+subject: "{{ 'order_group_mailer.store_owner_notification_email.subject' | t: store_name: store.name }}"
+---
+{% assign heading = 'order_group_mailer.store_owner_notification_email.purchase_summary' | t: number: order_group.number %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'order_group_mailer.store_owner_notification_email.heading' | t }}</mj-text>
+ <mj-text mj-class="lead">{{ 'order_group_mailer.store_owner_notification_email.instructions' | t: count: order_group.order_count }}</mj-text>
+ </mj-column>
+</mj-section>
+{% render 'spree/shared/order_summary', heading: heading, purchase: order_group, items: order_group.items, totals: true %}
diff --git a/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.text.erb b/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.text.erb
deleted file mode 100644
index 0caaf15ee5..0000000000
--- a/spree/emails/app/views/spree/order_group_mailer/store_owner_notification_email.text.erb
+++ /dev/null
@@ -1,11 +0,0 @@
-<%= Spree.t('order_group_mailer.store_owner_notification_email.instructions', count: @order_group.orders.size) %>
-
-============================================================
-<%= Spree.t('order_group_mailer.store_owner_notification_email.purchase_summary', number: @order_group.number) %>
-============================================================
-<%= render 'spree/shared/po_number', order: @order_group %>
-<% @order_group.line_items.each do |item| %>
- <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text -%> (<%= item.quantity %>) <%= Spree.t('at_symbol') %> <%= item.single_money %> = <%= item.display_amount %>
-<% end %>
-<%= render 'spree/shared/purchase_totals', order_group: @order_group %>
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/order_mailer/cancel_email.html.erb b/spree/emails/app/views/spree/order_mailer/cancel_email.html.erb
deleted file mode 100644
index 8ce8a4237c..0000000000
--- a/spree/emails/app/views/spree/order_mailer/cancel_email.html.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-<%= render 'spree/shared/purchased_items_styles' %>
-
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('order_mailer.cancel_email.subject') %></h1>
- <p class="greeting"><%= Spree.t('order_mailer.cancel_email.dear_customer', name: name_for(@order)) %></p>
- <p><%= Spree.t('order_mailer.cancel_email.instructions') %></p>
-<% end %>
-
-<%= render 'spree/shared/order_summary_section',
- heading: Spree.t('order_mailer.cancel_email.order_summary_canceled', number: @order.number),
- line_items: @order.line_items,
- order: @order %>
diff --git a/spree/emails/app/views/spree/order_mailer/cancel_email.liquid b/spree/emails/app/views/spree/order_mailer/cancel_email.liquid
new file mode 100644
index 0000000000..6c55139746
--- /dev/null
+++ b/spree/emails/app/views/spree/order_mailer/cancel_email.liquid
@@ -0,0 +1,12 @@
+---
+subject: "{% if resend %}[{{ 'resend' | t | upcase }}] {% endif %}{{ store.name }} {{ 'order_mailer.cancel_email.subject' | t }} #{{ order.number }}"
+---
+{% assign heading = 'order_mailer.cancel_email.order_summary_canceled' | t: number: order.number %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'order_mailer.cancel_email.subject' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'order_mailer.cancel_email.dear_customer' | t: name: order.customer_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'order_mailer.cancel_email.instructions' | t }}</mj-text>
+ </mj-column>
+</mj-section>
+{% render 'spree/shared/order_summary', heading: heading, purchase: order, items: order.items, totals: true %}
diff --git a/spree/emails/app/views/spree/order_mailer/cancel_email.text.erb b/spree/emails/app/views/spree/order_mailer/cancel_email.text.erb
deleted file mode 100755
index 5f1604241c..0000000000
--- a/spree/emails/app/views/spree/order_mailer/cancel_email.text.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-<%= Spree.t('order_mailer.cancel_email.dear_customer', name: name_for(@order)) %>
-
-<%= Spree.t('order_mailer.cancel_email.instructions') %>
-
-============================================================
-<%= Spree.t('order_mailer.cancel_email.order_summary_canceled', number: @order.number) %>
-============================================================
-<%= render 'spree/shared/po_number', order: @order %>
-<%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>
-============================================================
-<%= Spree.t('order_mailer.total') %> <%= @order.display_total %>
-<%= Spree.t('order_mailer.cancel_email.thanks') %>
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/order_mailer/confirm_email.html.erb b/spree/emails/app/views/spree/order_mailer/confirm_email.html.erb
deleted file mode 100644
index 17c562cee1..0000000000
--- a/spree/emails/app/views/spree/order_mailer/confirm_email.html.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-<%= render 'spree/shared/purchased_items_styles' %>
-
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('order_mailer.confirm_email.subject') %></h1>
- <p class="greeting"><%= Spree.t('order_mailer.confirm_email.dear_customer', name: name_for(@order)) %></p>
- <p><%= Spree.t('order_mailer.confirm_email.instructions') %></p>
-<% end %>
-
-<%= render 'spree/shared/order_summary_section',
- heading: Spree.t('order_mailer.confirm_email.order_summary', number: @order.number),
- line_items: @order.line_items,
- order: @order %>
diff --git a/spree/emails/app/views/spree/order_mailer/confirm_email.liquid b/spree/emails/app/views/spree/order_mailer/confirm_email.liquid
new file mode 100644
index 0000000000..678ea6d8e5
--- /dev/null
+++ b/spree/emails/app/views/spree/order_mailer/confirm_email.liquid
@@ -0,0 +1,12 @@
+---
+subject: "{% if resend %}[{{ 'resend' | t | upcase }}] {% endif %}{{ store.name }} {{ 'order_mailer.confirm_email.subject' | t }} #{{ order.number }}"
+---
+{% assign heading = 'order_mailer.confirm_email.order_summary' | t: number: order.number %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'order_mailer.confirm_email.subject' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'order_mailer.confirm_email.dear_customer' | t: name: order.customer_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'order_mailer.confirm_email.instructions' | t }}</mj-text>
+ </mj-column>
+</mj-section>
+{% render 'spree/shared/order_summary', heading: heading, purchase: order, items: order.items, totals: true %}
diff --git a/spree/emails/app/views/spree/order_mailer/confirm_email.text.erb b/spree/emails/app/views/spree/order_mailer/confirm_email.text.erb
deleted file mode 100644
index e84e8fca93..0000000000
--- a/spree/emails/app/views/spree/order_mailer/confirm_email.text.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-<%= Spree.t('order_mailer.confirm_email.dear_customer', name: name_for(@order)) %>
-
-<%= Spree.t('order_mailer.confirm_email.instructions') %>
-
-============================================================
-<%= Spree.t('order_mailer.confirm_email.order_summary', number: @order.number) %>
-============================================================
-<%= render 'spree/shared/po_number', order: @order %>
-<%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>
-============================================================
-<%= Spree.t('order_mailer.total') %> <%= @order.display_total %>
-<%= Spree.t('order_mailer.confirm_email.thanks') %>
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/order_mailer/payment_link_email.html.erb b/spree/emails/app/views/spree/order_mailer/payment_link_email.html.erb
deleted file mode 100644
index 7d65425a80..0000000000
--- a/spree/emails/app/views/spree/order_mailer/payment_link_email.html.erb
+++ /dev/null
@@ -1,11 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('order_mailer.payment_link_email.subject', number: @order.number) %></h1>
- <p class="greeting"><%= Spree.t('order_mailer.confirm_email.dear_customer', name: name_for(@order)) %></p>
- <p><%= Spree.t('order_mailer.payment_link_email.message', store_name: @current_store.name) %></p>
- <%= render 'spree/shared/mailer_button', url: @checkout_payment_url, label: Spree.t('order_mailer.payment_link_email.pay_for_order') %>
- <p class="sub">
- <%= Spree.t('order_mailer.payment_link_email.message_copy_link') %>
- <br>
- <%= link_to @checkout_payment_url, @checkout_payment_url %>
- </p>
-<% end %>
diff --git a/spree/emails/app/views/spree/order_mailer/payment_link_email.liquid b/spree/emails/app/views/spree/order_mailer/payment_link_email.liquid
new file mode 100644
index 0000000000..dd3d7dc168
--- /dev/null
+++ b/spree/emails/app/views/spree/order_mailer/payment_link_email.liquid
@@ -0,0 +1,12 @@
+---
+subject: "{{ 'order_mailer.payment_link_email.subject' | t: number: order.number }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'order_mailer.payment_link_email.subject' | t: number: order.number }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'order_mailer.confirm_email.dear_customer' | t: name: order.customer_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'order_mailer.payment_link_email.message' | t: store_name: store.name }}</mj-text>
+ <mj-button href="{{ payment_url }}">{{ 'order_mailer.payment_link_email.pay_for_order' | t }}</mj-button>
+ <mj-text mj-class="note">{{ 'order_mailer.payment_link_email.message_copy_link' | t }}<br /><a href="{{ payment_url }}">{{ payment_url }}</a></mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.html.erb b/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.html.erb
deleted file mode 100644
index 0a1d80b20a..0000000000
--- a/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.html.erb
+++ /dev/null
@@ -1,11 +0,0 @@
-<%= render 'spree/shared/purchased_items_styles' %>
-
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('order_mailer.store_owner_notification_email.heading') %></h1>
- <p><%= Spree.t('order_mailer.store_owner_notification_email.instructions') %></p>
-<% end %>
-
-<%= render 'spree/shared/order_summary_section',
- heading: Spree.t('order_mailer.store_owner_notification_email.order_summary', number: @order.number),
- line_items: @order.line_items,
- order: @order %>
diff --git a/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.liquid b/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.liquid
new file mode 100644
index 0000000000..85a262f34c
--- /dev/null
+++ b/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.liquid
@@ -0,0 +1,11 @@
+---
+subject: "{{ 'order_mailer.store_owner_notification_email.subject' | t: store_name: store.name }}"
+---
+{% assign heading = 'order_mailer.store_owner_notification_email.order_summary' | t: number: order.number %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'order_mailer.store_owner_notification_email.heading' | t }}</mj-text>
+ <mj-text mj-class="lead">{{ 'order_mailer.store_owner_notification_email.instructions' | t }}</mj-text>
+ </mj-column>
+</mj-section>
+{% render 'spree/shared/order_summary', heading: heading, purchase: order, items: order.items, totals: true %}
diff --git a/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.text.erb b/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.text.erb
deleted file mode 100644
index 1e85593a1b..0000000000
--- a/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.text.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-<%= Spree.t('order_mailer.store_owner_notification_email.heading') %>
-
-<%= Spree.t('order_mailer.store_owner_notification_email.instructions') %>
-
-============================================================
-<%= Spree.t('order_mailer.store_owner_notification_email.order_summary', number: @order.number) %>
-============================================================
-<%= render 'spree/shared/po_number', order: @order %>
-<%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>
-============================================================
-<%= Spree.t('order_mailer.total') %> <%= @order.display_total %>
-<%= Spree.t('order_mailer.store_owner_notification_email.thanks') %>
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/return_mailer/refunded_email.html.erb b/spree/emails/app/views/spree/return_mailer/refunded_email.html.erb
deleted file mode 100644
index 7d14fdc137..0000000000
--- a/spree/emails/app/views/spree/return_mailer/refunded_email.html.erb
+++ /dev/null
@@ -1,22 +0,0 @@
-<%= render 'spree/shared/purchased_items_styles' %>
-
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('return_mailer.refunded_email.subject') %></h1>
- <p class="greeting"><%= Spree.t('return_mailer.refunded_email.dear_customer', name: name_for(@order)) %></p>
- <p><%= Spree.t('return_mailer.refunded_email.instructions', number: @order.number) %></p>
-<% end %>
-
-<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td>
- <h3 class="f-fallback"><%= Spree.t('return_mailer.refunded_email.refund_summary') %></h3>
- <p class="strong f-fallback"><%= Spree.t('return_mailer.refunded_email.total_refunded', total: @return.display_refunded_total) %></p>
- </td>
- </tr>
-</table>
-
-<%= render 'spree/shared/order_summary_section',
- heading: Spree.t('return_mailer.refunded_email.returned_items'),
- line_items: @return.return_line_items.map(&:line_item),
- order: @order,
- totals: false %>
diff --git a/spree/emails/app/views/spree/return_mailer/refunded_email.liquid b/spree/emails/app/views/spree/return_mailer/refunded_email.liquid
new file mode 100644
index 0000000000..04912d0eec
--- /dev/null
+++ b/spree/emails/app/views/spree/return_mailer/refunded_email.liquid
@@ -0,0 +1,18 @@
+---
+subject: "{% if resend %}[{{ 'resend' | t | upcase }}] {% endif %}{{ store.name }} {{ 'return_mailer.refunded_email.subject' | t }} #{{ order.number }}"
+---
+{% assign heading = 'return_mailer.refunded_email.returned_items' | t %}
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'return_mailer.refunded_email.subject' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'return_mailer.refunded_email.dear_customer' | t: name: order.customer_name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'return_mailer.refunded_email.instructions' | t: number: order.number }}</mj-text>
+ </mj-column>
+</mj-section>
+<mj-section padding="48px 0 0">
+ <mj-column>
+ <mj-text mj-class="section-heading" padding="0 0 16px">{{ 'return_mailer.refunded_email.refund_summary' | t }}</mj-text>
+ <mj-text mj-class="body" padding="0" font-weight="500" color="#332C2C">{{ 'return_mailer.refunded_email.total_refunded' | t: total: return.display_refunded_total }}</mj-text>
+ </mj-column>
+</mj-section>
+{% render 'spree/shared/order_summary', heading: heading, purchase: order, items: return.returned_items, totals: false %}
diff --git a/spree/emails/app/views/spree/return_mailer/refunded_email.text.erb b/spree/emails/app/views/spree/return_mailer/refunded_email.text.erb
deleted file mode 100644
index d7c515958b..0000000000
--- a/spree/emails/app/views/spree/return_mailer/refunded_email.text.erb
+++ /dev/null
@@ -1,20 +0,0 @@
-<%= Spree.t('return_mailer.refunded_email.dear_customer', name: name_for(@order)) %>
-
-<%= Spree.t('return_mailer.refunded_email.instructions', number: @order.number) %>
-
-============================================================
-<%= Spree.t('return_mailer.refunded_email.refund_summary') %>
-============================================================
-<%= render 'spree/shared/po_number', order: @order %>
-<%= Spree.t('return_mailer.refunded_email.total_refunded', total: @return.display_refunded_total) %>
-
-============================================================
-<%= Spree.t('return_mailer.refunded_email.returned_items') %>
-============================================================
-<% @return.return_line_items.each do |line| %>
- <%= line.variant.sku %> <%= line.variant.product.name %> <%= line.variant.options_text %>
-<% end %>
-============================================================
-
-<%= Spree.t('return_mailer.refunded_email.thanks') %>
-<%= Spree.t('return_mailer.refunded_email.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/seller_mailer/approved_email.html.erb b/spree/emails/app/views/spree/seller_mailer/approved_email.html.erb
deleted file mode 100644
index b042701c01..0000000000
--- a/spree/emails/app/views/spree/seller_mailer/approved_email.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('seller_mailer.approved_email.heading') %></h1>
- <p class="greeting"><%= Spree.t('seller_mailer.greeting', seller_name: @seller.name) %></p>
- <p><%= Spree.t('seller_mailer.approved_email.message', store_name: current_store.name) %></p>
- <% if @dashboard_url %>
- <%= render 'spree/shared/mailer_button', url: @dashboard_url, label: Spree.t('seller_mailer.approved_email.action') %>
- <% end %>
-<% end %>
diff --git a/spree/emails/app/views/spree/seller_mailer/approved_email.liquid b/spree/emails/app/views/spree/seller_mailer/approved_email.liquid
new file mode 100644
index 0000000000..86715be855
--- /dev/null
+++ b/spree/emails/app/views/spree/seller_mailer/approved_email.liquid
@@ -0,0 +1,13 @@
+---
+subject: "{{ 'seller_mailer.approved_email.subject' | t: store_name: store.name }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'seller_mailer.approved_email.heading' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'seller_mailer.greeting' | t: seller_name: seller.name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'seller_mailer.approved_email.message' | t: store_name: store.name }}</mj-text>
+ {% if dashboard_url %}
+ <mj-button href="{{ dashboard_url }}">{{ 'seller_mailer.approved_email.action' | t }}</mj-button>
+ {% endif %}
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/seller_mailer/approved_email.text.erb b/spree/emails/app/views/spree/seller_mailer/approved_email.text.erb
deleted file mode 100644
index 613550783f..0000000000
--- a/spree/emails/app/views/spree/seller_mailer/approved_email.text.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<%= Spree.t('seller_mailer.greeting', seller_name: @seller.name) %>
-
-<%= Spree.t('seller_mailer.approved_email.message', store_name: current_store.name) %>
-<% if @dashboard_url %>
-<%= Spree.t('seller_mailer.approved_email.action') %>: <%= @dashboard_url %>
-<% end %>
-
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/seller_mailer/rejected_email.html.erb b/spree/emails/app/views/spree/seller_mailer/rejected_email.html.erb
deleted file mode 100644
index 19a7ad7243..0000000000
--- a/spree/emails/app/views/spree/seller_mailer/rejected_email.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('seller_mailer.rejected_email.heading') %></h1>
- <p class="greeting"><%= Spree.t('seller_mailer.greeting', seller_name: @seller.name) %></p>
- <p><%= Spree.t('seller_mailer.rejected_email.message', store_name: current_store.name) %></p>
- <p class="sub"><%= Spree.t('seller_mailer.get_in_touch', store_email: current_store.mail_from_address) %></p>
-<% end %>
diff --git a/spree/emails/app/views/spree/seller_mailer/rejected_email.liquid b/spree/emails/app/views/spree/seller_mailer/rejected_email.liquid
new file mode 100644
index 0000000000..d533dd3eb5
--- /dev/null
+++ b/spree/emails/app/views/spree/seller_mailer/rejected_email.liquid
@@ -0,0 +1,11 @@
+---
+subject: "{{ 'seller_mailer.rejected_email.subject' | t: store_name: store.name }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'seller_mailer.rejected_email.heading' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'seller_mailer.greeting' | t: seller_name: seller.name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'seller_mailer.rejected_email.message' | t: store_name: store.name }}</mj-text>
+ <mj-text mj-class="note">{{ 'seller_mailer.get_in_touch' | t: store_email: store.mail_from_address }}</mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/seller_mailer/rejected_email.text.erb b/spree/emails/app/views/spree/seller_mailer/rejected_email.text.erb
deleted file mode 100644
index c50142aec6..0000000000
--- a/spree/emails/app/views/spree/seller_mailer/rejected_email.text.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-<%= Spree.t('seller_mailer.greeting', seller_name: @seller.name) %>
-
-<%= Spree.t('seller_mailer.rejected_email.message', store_name: current_store.name) %>
-
-<%= Spree.t('seller_mailer.get_in_touch', store_email: current_store.mail_from_address) %>
-
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/seller_mailer/suspended_email.html.erb b/spree/emails/app/views/spree/seller_mailer/suspended_email.html.erb
deleted file mode 100644
index 1660d0767f..0000000000
--- a/spree/emails/app/views/spree/seller_mailer/suspended_email.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-<%= render layout: 'spree/shared/mailer_hero' do %>
- <h1><%= Spree.t('seller_mailer.suspended_email.heading') %></h1>
- <p class="greeting"><%= Spree.t('seller_mailer.greeting', seller_name: @seller.name) %></p>
- <p><%= Spree.t('seller_mailer.suspended_email.message', store_name: current_store.name) %></p>
- <p class="sub"><%= Spree.t('seller_mailer.get_in_touch', store_email: current_store.mail_from_address) %></p>
-<% end %>
diff --git a/spree/emails/app/views/spree/seller_mailer/suspended_email.liquid b/spree/emails/app/views/spree/seller_mailer/suspended_email.liquid
new file mode 100644
index 0000000000..d81aeb0bf7
--- /dev/null
+++ b/spree/emails/app/views/spree/seller_mailer/suspended_email.liquid
@@ -0,0 +1,11 @@
+---
+subject: "{{ 'seller_mailer.suspended_email.subject' | t: store_name: store.name }}"
+---
+<mj-section>
+ <mj-column css-class="hero">
+ <mj-text mj-class="heading">{{ 'seller_mailer.suspended_email.heading' | t }}</mj-text>
+ <mj-text mj-class="greeting">{{ 'seller_mailer.greeting' | t: seller_name: seller.name }}</mj-text>
+ <mj-text mj-class="lead">{{ 'seller_mailer.suspended_email.message' | t: store_name: store.name }}</mj-text>
+ <mj-text mj-class="note">{{ 'seller_mailer.get_in_touch' | t: store_email: store.mail_from_address }}</mj-text>
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/seller_mailer/suspended_email.text.erb b/spree/emails/app/views/spree/seller_mailer/suspended_email.text.erb
deleted file mode 100644
index d21ccb973f..0000000000
--- a/spree/emails/app/views/spree/seller_mailer/suspended_email.text.erb
+++ /dev/null
@@ -1,7 +0,0 @@
-<%= Spree.t('seller_mailer.greeting', seller_name: @seller.name) %>
-
-<%= Spree.t('seller_mailer.suspended_email.message', store_name: current_store.name) %>
-
-<%= Spree.t('seller_mailer.get_in_touch', store_email: current_store.mail_from_address) %>
-
-<%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
diff --git a/spree/emails/app/views/spree/shared/_fulfillment_group.liquid b/spree/emails/app/views/spree/shared/_fulfillment_group.liquid
new file mode 100644
index 0000000000..68783db186
--- /dev/null
+++ b/spree/emails/app/views/spree/shared/_fulfillment_group.liquid
@@ -0,0 +1,20 @@
+{%- comment -%}
+ One real parcel of a purchase: the goods it carries and what it cost to
+ deliver. A purchase arriving in one parcel is not numbered.
+ Arguments: group, position, count.
+{%- endcomment -%}
+<mj-section padding="48px 0 0">
+ <mj-column>
+ <mj-text mj-class="section-heading" padding="0 0 16px">
+ {%- if count > 1 -%}{{ 'order_group_mailer.delivery_numbered' | t: position: position, count: count }}{%- else -%}{{ 'order_group_mailer.delivery' | t }}{%- endif -%}
+ </mj-text>
+ {%- if group.seller_names.size > 0 -%}
+ {%- assign sellers = group.seller_names | join: ', ' -%}
+ <mj-text mj-class="note" align="left" padding="0 0 16px">{{ 'order_group_mailer.sold_by' | t: sellers: sellers }}</mj-text>
+ {%- endif -%}
+ {% render 'spree/shared/line_item' for group.items as item %}
+ <mj-table css-class="summary" padding="16px 0 0">
+ {% render 'spree/shared/summary_row', label: 'shipping', translate: true, sub: group.name, value: group.display_cost %}
+ </mj-table>
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/shared/_fulfillment_group_section.html.erb b/spree/emails/app/views/spree/shared/_fulfillment_group_section.html.erb
deleted file mode 100644
index 5a35ca8337..0000000000
--- a/spree/emails/app/views/spree/shared/_fulfillment_group_section.html.erb
+++ /dev/null
@@ -1,37 +0,0 @@
-<%# One real parcel of a purchase, with the goods it carries and what it cost
- to deliver. Locals: fulfillment_group, position, count.
-
- A purchase arriving in one parcel is not numbered — "Delivery 1 of 1"
- tells the customer nothing they did not already assume.
-
- Rendered from the parcel's manifest rather than its line items: a line
- packed from two warehouses travels in two parcels, and its own quantity
- describes the whole order rather than this box. %>
-<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td>
- <h3 class="f-fallback">
- <% if count > 1 %>
- <%= Spree.t('order_group_mailer.delivery_numbered', position: position, count: count) %>
- <% else %>
- <%= Spree.t('order_group_mailer.delivery') %>
- <% end %>
- </h3>
- <% if fulfillment_group.sellers.any? %>
- <p class="f-fallback sub"><%= Spree.t('order_group_mailer.sold_by', sellers: fulfillment_group.sellers.map(&:name).to_sentence) %></p>
- <% end %>
- <% fulfillment_group.manifest.each do |item| %>
- <%= render 'spree/shared/purchased_items_table/line_item',
- line_item: item.line_item,
- quantity: item.quantity,
- amount: Spree::Money.new(item.line_item.price * item.quantity, currency: item.line_item.currency) %>
- <% end %>
- <table class="summary purchase_content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t(:shipping),
- sub: fulfillment_group.name,
- value: fulfillment_group.display_cost %>
- </table>
- </td>
- </tr>
-</table>
diff --git a/spree/emails/app/views/spree/shared/_fulfillment_group_section.text.erb b/spree/emails/app/views/spree/shared/_fulfillment_group_section.text.erb
deleted file mode 100644
index 615333e5b1..0000000000
--- a/spree/emails/app/views/spree/shared/_fulfillment_group_section.text.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-<% if count > 1 %>
-<%= Spree.t('order_group_mailer.delivery_numbered', position: position, count: count) %>
-<% else %>
-<%= Spree.t('order_group_mailer.delivery') %>
-<% end %>
-<% if fulfillment_group.sellers.any? %>
-<%= Spree.t('order_group_mailer.sold_by', sellers: fulfillment_group.sellers.map(&:name).to_sentence) %>
-<% end %>
-<% fulfillment_group.manifest.each do |item| %>
- <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text -%> (<%= item.quantity %>) <%= Spree.t('at_symbol') %> <%= item.line_item.single_money %> = <%= Spree::Money.new(item.line_item.price * item.quantity, currency: item.line_item.currency) %>
-<% end %>
- <%= Spree.t(:shipping) %>: <%= fulfillment_group.name %> <%= fulfillment_group.display_cost %>
diff --git a/spree/emails/app/views/spree/shared/_item_thumbnail_link.html.erb b/spree/emails/app/views/spree/shared/_item_thumbnail_link.html.erb
deleted file mode 100644
index af96165779..0000000000
--- a/spree/emails/app/views/spree/shared/_item_thumbnail_link.html.erb
+++ /dev/null
@@ -1,18 +0,0 @@
-<%# Rounded 80px product thumbnail linking to the product page, with a
- no-image fallback. Locals: image, product_url, alt. %>
-<% if image.present? && image.attached? %>
- <%= link_to spree_image_tag(image, variant: :small, alt: alt, width: 80, class: 'item_thumb'), product_url %>
-<% else %>
- <%# Table + inline styles, not a styled div: Outlook collapses empty block
- elements and ignores class-based height, and a div inside <a> is invalid
- under the XHTML doctype the mailer layout declares. %>
- <table class="item_thumb_placeholder" width="80" height="80" cellpadding="0" cellspacing="0" role="presentation"
- style="width: 80px; height: 80px; background-color: #E4E4E4; border-radius: 12px;">
- <tr>
- <td width="80" height="80" style="width: 80px; height: 80px; line-height: 80px; font-size: 0;">
- <%= link_to '&#160;'.html_safe, product_url, 'aria-label': alt,
- style: 'display: block; width: 80px; height: 80px; line-height: 80px; text-decoration: none;' %>
- </td>
- </tr>
- </table>
-<% end %>
diff --git a/spree/emails/app/views/spree/shared/_line_item.liquid b/spree/emails/app/views/spree/shared/_line_item.liquid
new file mode 100644
index 0000000000..da143044b5
--- /dev/null
+++ b/spree/emails/app/views/spree/shared/_line_item.liquid
@@ -0,0 +1,29 @@
+{%- comment -%}
+ One purchased line as a tile: thumbnail, name, options, quantity and amount.
+ Arguments: item.
+{%- endcomment -%}
+<mj-table padding="0 0 8px">
+ <tr>
+ <td>
+ <table class="item" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="width: 100%; background-color: #F0F0F0; border-radius: 16px;">
+ <tr>
+ <td class="item_image" width="96" valign="middle" style="padding: 8px; width: 96px;">
+ {%- if item.image_url -%}
+ <a href="{{ item.url }}"><img src="{{ item.image_url }}" alt="{{ item.name }}" width="80" class="item_thumb" style="display: block; width: 80px; height: auto; border-radius: 12px;" /></a>
+ {%- else -%}
+ <a href="{{ item.url }}" aria-label="{{ item.name }}" style="display: block; width: 80px; height: 80px; background-color: #E4E4E4; border-radius: 12px; text-decoration: none;">&#160;</a>
+ {%- endif -%}
+ </td>
+ <td class="item_info" valign="middle">
+ <a href="{{ item.url }}" class="item_name">{{ item.name }}</a>
+ {%- if item.options_text != blank -%}<p class="item_meta">{{ item.options_text }}</p>{%- endif -%}
+ </td>
+ <td class="item_amount" align="right" valign="middle">
+ <p class="item_qty">{{ item.quantity }} x {{ item.display_price }}</p>
+ <p class="item_price">{{ item.display_amount }}</p>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</mj-table>
diff --git a/spree/emails/app/views/spree/shared/_order_summary.liquid b/spree/emails/app/views/spree/shared/_order_summary.liquid
new file mode 100644
index 0000000000..8fc605951c
--- /dev/null
+++ b/spree/emails/app/views/spree/shared/_order_summary.liquid
@@ -0,0 +1,17 @@
+{%- comment -%}
+ A headed list of purchased lines, with the purchase's totals unless the
+ lines are only part of it (one parcel's items, say).
+ Arguments: heading, purchase, items, totals.
+{%- endcomment -%}
+<mj-section padding="48px 0 0">
+ <mj-column>
+ <mj-text mj-class="section-heading" padding="0 0 16px">{{ heading }}</mj-text>
+ {%- if purchase.po_number != blank -%}
+ <mj-text mj-class="body" padding="0 0 16px">{{ 'order_mailer.po_number' | t: number: purchase.po_number }}</mj-text>
+ {%- endif -%}
+ {% render 'spree/shared/line_item' for items as item %}
+ {%- if totals -%}
+ {% render 'spree/shared/purchase_totals', purchase: purchase %}
+ {%- endif -%}
+ </mj-column>
+</mj-section>
diff --git a/spree/emails/app/views/spree/shared/_order_summary_section.html.erb b/spree/emails/app/views/spree/shared/_order_summary_section.html.erb
deleted file mode 100644
index 631d83f4f6..0000000000
--- a/spree/emails/app/views/spree/shared/_order_summary_section.html.erb
+++ /dev/null
@@ -1,20 +0,0 @@
-<%# Labelled line-items + totals section shared by the order-related emails.
- Locals: heading, line_items, order, optional totals (default true — pass
- false when line_items is a subset of the order, e.g. one shipment's items,
- so whole-order amounts aren't shown next to a partial item list). %>
-<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td>
- <h3 class="f-fallback"><%= heading %></h3>
- <%# The buyer's own purchase-order reference, when they gave one — it is
- how their accounting reconciles this order. %>
- <% if order.po_number.present? %>
- <p class="f-fallback"><%= Spree.t('order_mailer.po_number', number: order.po_number) %></p>
- <% end %>
- <%= render 'spree/shared/purchased_items_table',
- line_items: line_items,
- order: order,
- totals: local_assigns.fetch(:totals, true) %>
- </td>
- </tr>
-</table>
diff --git a/spree/emails/app/views/spree/shared/_po_number.text.erb b/spree/emails/app/views/spree/shared/_po_number.text.erb
deleted file mode 100644
index 2a94f288cf..0000000000
--- a/spree/emails/app/views/spree/shared/_po_number.text.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-<%# The buyer's own purchase-order reference, when they gave one. Rendered by
- every order-facing document so their accounting can reconcile against it.
- Locals: order. %>
-<% if order.po_number.present? %>
-<%= Spree.t('order_mailer.po_number', number: order.po_number) %>
-<% end %>
diff --git a/spree/emails/app/views/spree/shared/_purchase_totals.html.erb b/spree/emails/app/views/spree/shared/_purchase_totals.html.erb
deleted file mode 100644
index 15631e2ef4..0000000000
--- a/spree/emails/app/views/spree/shared/_purchase_totals.html.erb
+++ /dev/null
@@ -1,62 +0,0 @@
-<%# Every figure of the whole purchase, once. Locals: order_group.
-
- Deliberately not the order summary's own totals block: that one reaches
- into one order's fulfillments and money rows, and a purchase has neither
- of its own. These read the group's roll-up of what each child independently
- computed. Delivery is one line here and broken down per parcel above. %>
-<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td>
- <h3 class="f-fallback"><%= Spree.t(:order_summary) %></h3>
- <table class="summary purchase_content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t('order_mailer.subtotal'),
- value: order_group.display_item_total %>
-
- <% order_group.discounts.promotion.to_a.group_by(&:label).each do |label, discounts| %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t(:promotion),
- sub: label,
- value: Spree::Money.new(discounts.sum(&:amount), currency: order_group.currency) %>
- <% end %>
-
- <% if order_group.delivery_total != 0 %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t(:shipping),
- value: order_group.display_delivery_total %>
- <% end %>
-
- <% if order_group.additional_tax_total != 0 %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t(:tax),
- value: order_group.display_additional_tax_total %>
- <% end %>
-
- <% if order_group.gift_card_total.positive? %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t(:gift_card),
- value: safe_join(['-', order_group.display_gift_card_total.to_html]) %>
- <% end %>
-
- <% order_group.discounts.manual.to_a.group_by(&:label).each do |label, discounts| %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: label,
- value: Spree::Money.new(discounts.sum(&:amount), currency: order_group.currency) %>
- <% end %>
-
- <% order_group.fees.to_a.group_by(&:label).each do |label, fees| %>
- <% amount = fees.sum(&:amount) %>
- <% next if amount.zero? %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: label,
- value: Spree::Money.new(amount, currency: order_group.currency) %>
- <% end %>
-
- <%= render 'spree/shared/purchased_items_table/summary_row',
- row_class: 'summary_total',
- label: Spree.t('order_mailer.total'),
- value: order_group.display_total_minus_store_credits %>
- </table>
- </td>
- </tr>
-</table>
diff --git a/spree/emails/app/views/spree/shared/_purchase_totals.liquid b/spree/emails/app/views/spree/shared/_purchase_totals.liquid
new file mode 100644
index 0000000000..3a868dbb52
--- /dev/null
+++ b/spree/emails/app/views/spree/shared/_purchase_totals.liquid
@@ -0,0 +1,28 @@
+{%- comment -%}
+ Every figure of an order or a purchase, once. Arguments: purchase.
+{%- endcomment -%}
+{%- assign tax_total = purchase.additional_tax_total | plus: 0 -%}
+{%- assign gift_card_total = purchase.gift_card_total | plus: 0 -%}
+<mj-table css-class="summary" padding="16px 0 0">
+ {% render 'spree/shared/summary_row', label: 'order_mailer.subtotal', translate: true, value: purchase.display_item_total %}
+ {%- for line in purchase.promotion_discounts -%}
+ {% render 'spree/shared/summary_row', label: 'promotion', translate: true, sub: line.label, value: line.display_amount %}
+ {%- endfor -%}
+ {%- for line in purchase.delivery_lines -%}
+ {% render 'spree/shared/summary_row', label: 'shipping', translate: true, sub: line.label, value: line.display_amount %}
+ {%- endfor -%}
+ {%- if tax_total != 0 -%}
+ {% render 'spree/shared/summary_row', label: 'tax', translate: true, value: purchase.display_additional_tax_total %}
+ {%- endif -%}
+ {%- if gift_card_total > 0 -%}
+ {%- assign gift_card_value = purchase.display_gift_card_total | prepend: '-' -%}
+ {% render 'spree/shared/summary_row', label: 'gift_card', translate: true, value: gift_card_value %}
+ {%- endif -%}
+ {%- for line in purchase.manual_discounts -%}
+ {% render 'spree/shared/summary_row', label: line.label, value: line.display_amount %}
+ {%- endfor -%}
+ {%- for line in purchase.fee_lines -%}
+ {% render 'spree/shared/summary_row', label: line.label, value: line.display_amount %}
+ {%- endfor -%}
+ {% render 'spree/shared/summary_row', label: 'order_mailer.total', translate: true, value: purchase.display_total_minus_store_credits, total: true %}
+</mj-table>
diff --git a/spree/emails/app/views/spree/shared/_purchase_totals.text.erb b/spree/emails/app/views/spree/shared/_purchase_totals.text.erb
deleted file mode 100644
index af817c13a2..0000000000
--- a/spree/emails/app/views/spree/shared/_purchase_totals.text.erb
+++ /dev/null
@@ -1,24 +0,0 @@
-============================================================
-<%= Spree.t('order_mailer.subtotal') %> <%= order_group.display_item_total %>
-<% order_group.discounts.promotion.to_a.group_by(&:label).each do |label, discounts| %>
- <%= Spree.t(:promotion) %>: <%= label %> <%= Spree::Money.new(discounts.sum(&:amount), currency: order_group.currency) %>
-<% end %>
-<% if order_group.delivery_total != 0 %>
- <%= Spree.t(:shipping) %>: <%= order_group.display_delivery_total %>
-<% end %>
-<% if order_group.additional_tax_total != 0 %>
- <%= Spree.t(:tax) %>: <%= order_group.display_additional_tax_total %>
-<% end %>
-<% if order_group.gift_card_total.positive? %>
- <%= Spree.t(:gift_card) %>: -<%= order_group.display_gift_card_total %>
-<% end %>
-<% order_group.discounts.manual.to_a.group_by(&:label).each do |label, discounts| %>
- <%= label %> <%= Spree::Money.new(discounts.sum(&:amount), currency: order_group.currency) %>
-<% end %>
-<% order_group.fees.to_a.group_by(&:label).each do |label, fees| %>
- <% amount = fees.sum(&:amount) %>
- <% next if amount.zero? %>
- <%= label %> <%= Spree::Money.new(amount, currency: order_group.currency) %>
-<% end %>
-============================================================
-<%= Spree.t('order_mailer.total') %> <%= order_group.display_total_minus_store_credits %>
diff --git a/spree/emails/app/views/spree/shared/_purchased_items_table.html.erb b/spree/emails/app/views/spree/shared/_purchased_items_table.html.erb
deleted file mode 100644
index 4e0d8be9cb..0000000000
--- a/spree/emails/app/views/spree/shared/_purchased_items_table.html.erb
+++ /dev/null
@@ -1,41 +0,0 @@
-<%= render collection: line_items, partial: 'spree/shared/purchased_items_table/line_item', as: :line_item %>
-
-<% if local_assigns.fetch(:totals, true) %>
-<table class="summary purchase_content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <%= render 'spree/shared/purchased_items_table/subtotal', order: order %>
- <% order.discounts.promotion.to_a.group_by(&:label).each do |label, discounts| %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t(:promotion),
- sub: label,
- value: Spree::Money.new(discounts.sum(&:amount), currency: order.currency) %>
- <% end %>
- <% order.fulfillments.group_by { |f| f.selected_delivery_rate&.name }.each do |name, shipments| %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t(:shipping),
- sub: name,
- value: Spree::Money.new(shipments.sum(&:cost), currency: order.currency) %>
- <% end %>
- <% if order.additional_tax_total != 0 %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t(:tax),
- value: order.display_additional_tax_total %>
- <% end %>
- <% if order.gift_card_total.positive? %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t(:gift_card),
- value: safe_join(['-', order.display_gift_card_total.to_html]) %>
- <% end %>
- <% order.discounts.manual.to_a.group_by(&:label).each do |label, discounts| %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: label,
- value: Spree::Money.new(discounts.sum(&:amount), currency: order.currency) %>
- <% end %>
- <% order.fees.each do |fee| %>
- <% next if fee.amount == 0 %>
- <%= render 'spree/shared/purchased_items_table/summary_row',
- label: fee.label,
- value: Spree::Money.new(fee.amount, currency: order.currency) %>
- <% end %>
- <%= render 'spree/shared/purchased_items_table/total', order: order %>
-</table>
-<% end %>
diff --git a/spree/emails/app/views/spree/shared/_purchased_items_table.text.erb b/spree/emails/app/views/spree/shared/_purchased_items_table.text.erb
deleted file mode 100644
index bea3dd9185..0000000000
--- a/spree/emails/app/views/spree/shared/_purchased_items_table.text.erb
+++ /dev/null
@@ -1,28 +0,0 @@
-<% line_items.each do |item| %>
- <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text -%> (<%=item.quantity%>) <%= Spree.t('at_symbol') %> <%= item.single_money %> = <%= item.display_amount %>
-<% end %>
-============================================================
-<%= Spree.t('order_mailer.subtotal') %> <%= order.display_item_total %>
-<% order.discounts.promotion.to_a.group_by(&:label).each do |label, discounts| %>
- <%= Spree.t(:promotion) %>: <%= label %> <%= Spree::Money.new(discounts.sum(&:amount), currency: order.currency) %>
-<% end %>
-
-<% order.fulfillments.group_by { |f| f.selected_delivery_rate.try(:name) }.each do |name, shipments| %>
- <%= Spree.t(:shipping) %>: <%= name %> <%= Spree::Money.new(shipments.sum(&:cost), currency: order.currency) %>
-<% end %>
-
-<% if order.additional_tax_total != 0 %>
- <%= Spree.t(:tax) %>: <%= order.display_additional_tax_total.to_html %>
-<% end %>
-
-<% if order.gift_card_total.positive? %>
- <%= Spree.t(:gift_card) %>: -<%= order.display_gift_card_total.to_html %>
-<% end %>
-
-<% order.discounts.manual.to_a.group_by(&:label).each do |label, discounts| %>
- <%= label %> <%= Spree::Money.new(discounts.sum(&:amount), currency: order.currency) %>
-<% end %>
-<% order.fees.each do |fee| %>
- <% next if fee.amount == 0 %>
- <%= fee.label %> <%= fee.display_amount %>
-<% end %>
diff --git a/spree/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb b/spree/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb
deleted file mode 100644
index 4f5e13a68c..0000000000
--- a/spree/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb
+++ /dev/null
@@ -1,24 +0,0 @@
-<%# One purchased line. Locals: line_item, and optionally quantity + amount
- for a view showing part of a line — a parcel carrying two of the three
- ordered, say — where the line's own figures describe more than is there. %>
-<% quantity = local_assigns.fetch(:quantity, line_item.quantity) %>
-<% amount = local_assigns.fetch(:amount, line_item.display_amount) %>
-<table class="item" width="100%" cellpadding="0" cellspacing="0" role="presentation">
- <tr>
- <td class="item_image" width="96" valign="middle">
- <% image = line_item.variant.primary_media || line_item.product.primary_media %>
- <% product_url = spree_storefront_resource_url(line_item.product) %>
- <%= render 'spree/shared/item_thumbnail_link', image: image, product_url: product_url, alt: line_item.name %>
- </td>
- <td class="item_info" valign="middle">
- <%= link_to line_item.name, product_url, class: 'f-fallback item_name' %>
- <% if line_item.variant.options_text.present? %>
- <p class="item_meta"><%= line_item.variant.options_text %></p>
- <% end %>
- </td>
- <td class="item_amount" align="right" valign="middle">
- <p class="item_qty f-fallback"><%= quantity %> x <%= line_item.single_money %></p>
- <p class="item_price f-fallback"><%= amount %></p>
- </td>
- </tr>
-</table>
diff --git a/spree/emails/app/views/spree/shared/purchased_items_table/_subtotal.html.erb b/spree/emails/app/views/spree/shared/purchased_items_table/_subtotal.html.erb
deleted file mode 100644
index 615ea0d23e..0000000000
--- a/spree/emails/app/views/spree/shared/purchased_items_table/_subtotal.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= render 'spree/shared/purchased_items_table/summary_row',
- label: Spree.t('order_mailer.subtotal'),
- value: order.display_item_total %>
diff --git a/spree/emails/app/views/spree/shared/purchased_items_table/_summary_row.html.erb b/spree/emails/app/views/spree/shared/purchased_items_table/_summary_row.html.erb
deleted file mode 100644
index e002c0bda1..0000000000
--- a/spree/emails/app/views/spree/shared/purchased_items_table/_summary_row.html.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-<%# One label/value row of the order summary. Locals: label, value,
- optional sub (secondary line under the label, e.g. the shipping rate name),
- optional row_class ('summary_total' for the emphasized final row). %>
-<tr class="<%= local_assigns[:row_class] %>">
- <td valign="top">
- <span class="f-fallback"><%= label %></span>
- <% if local_assigns[:sub].present? %>
- <span class="f-fallback summary_sub"><%= sub %></span>
- <% end %>
- </td>
- <td class="summary_value" align="right" valign="top">
- <span class="f-fallback"><%= value.respond_to?(:to_html) ? value.to_html : value %></span>
- </td>
-</tr>
diff --git a/spree/emails/app/views/spree/shared/purchased_items_table/_total.html.erb b/spree/emails/app/views/spree/shared/purchased_items_table/_total.html.erb
deleted file mode 100644
index c2cf68ac1b..0000000000
--- a/spree/emails/app/views/spree/shared/purchased_items_table/_total.html.erb
+++ /dev/null
@@ -1,4 +0,0 @@
-<%= render 'spree/shared/purchased_items_table/summary_row',
- row_class: 'summary_total',
- label: Spree.t('order_mailer.total'),
- value: order.display_total_minus_store_credits %>
diff --git a/spree/emails/spec/helpers/spree/base_helper_spec.rb b/spree/emails/spec/helpers/spree/base_helper_spec.rb
deleted file mode 100644
index 84bfa84176..0000000000
--- a/spree/emails/spec/helpers/spree/base_helper_spec.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-require 'spec_helper'
-
-describe Spree::BaseHelper, type: :helper do
- include described_class
-
- let(:current_store) { create(:store) }
-
- before do
- allow(controller).to receive(:controller_name).and_return('test')
- allow(Rails.application.routes).to receive(:default_url_options).and_return(protocol: 'http', port: nil)
- end
-
- describe '#spree_storefront_resource_url' do
- let!(:store) { @default_store }
- let!(:category) { create(:category) }
- let!(:product) { create(:product) }
-
- before do
- allow(helper).to receive(:current_store).and_return(store)
- end
-
- context 'for Product URL' do
- it { expect(helper.spree_storefront_resource_url(product)).to eq("http://www.example.com/products/#{product.slug}") }
-
- context 'when a locale is passed' do
- it { expect(helper.spree_storefront_resource_url(product, locale: :de)).to eq("http://www.example.com/de/products/#{product.slug}") }
- end
-
- context 'when preview_id is not present' do
- it 'returns the product url' do
- expect(spree_storefront_resource_url(product)).to eq("http://#{current_store.url}/products/#{product.slug}")
- end
- end
-
- context 'when preview_id is present' do
- it 'returns the product preview url' do
- expect(spree_storefront_resource_url(product, preview_id: product.id)).to eq("http://#{current_store.url}/products/#{product.slug}?preview_id=#{product.id}")
- end
- end
-
- context 'for product with relative option' do
- it 'returns the product url' do
- expect(spree_storefront_resource_url(product, relative: true)).to eq("/products/#{product.slug}")
- end
- end
- end
-
- context 'for Category URL' do
- it { expect(helper.spree_storefront_resource_url(category)).to eq("http://www.example.com/t/#{category.permalink}") }
-
- context 'when a locale is passed' do
- it { expect(helper.spree_storefront_resource_url(category, locale: :de)).to eq("http://www.example.com/de/t/#{category.permalink}") }
- end
- end
- end
-end
diff --git a/spree/emails/spec/helpers/spree/mail_helper_spec.rb b/spree/emails/spec/helpers/spree/mail_helper_spec.rb
deleted file mode 100644
index f7ccc98d9d..0000000000
--- a/spree/emails/spec/helpers/spree/mail_helper_spec.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require 'spec_helper'
-
-module Spree
- describe MailHelper, type: :helper do
- let(:store) { @default_store }
-
- before do
- allow(helper).to receive(:current_store) { store }
- end
-
- describe '#name_for' do
- subject { helper.name_for(order) }
-
- let(:order) { create(:order, ship_address_id: nil, bill_address_id: nil, store: store) }
- let(:address) { create(:address) }
-
- context 'without address' do
- it 'shows default name' do
- expect(subject).to eq Spree.t('customer')
- end
- end
-
- context 'with address' do
- before do
- order.update(ship_address: address)
- end
-
- it 'shows customer full name' do
- expect(subject).to eq address.full_name
- end
- end
- end
- end
-end
diff --git a/spree/emails/spec/mailers/spree/digital_asset_mailer_spec.rb b/spree/emails/spec/mailers/spree/digital_asset_mailer_spec.rb
index d6b8fa67d1..765b4f5e7b 100644
--- a/spree/emails/spec/mailers/spree/digital_asset_mailer_spec.rb
+++ b/spree/emails/spec/mailers/spree/digital_asset_mailer_spec.rb
@@ -23,7 +23,7 @@ describe Spree::DigitalAssetMailer, type: :mailer do
end
it 'links every purchased file with an absolute url' do
- body = message.body.encoded
+ body = email_body(message)
expect(body).to include(digital_link.filename.to_s)
expect(body).to match(%r{https?://[^"\s]+/api/v3/store/digital_links/#{digital_link.token}})
diff --git a/spree/emails/spec/mailers/spree/newsletter_mailer_spec.rb b/spree/emails/spec/mailers/spree/newsletter_mailer_spec.rb
index b40ed3205f..b91982a272 100644
--- a/spree/emails/spec/mailers/spree/newsletter_mailer_spec.rb
+++ b/spree/emails/spec/mailers/spree/newsletter_mailer_spec.rb
@@ -19,7 +19,7 @@ describe Spree::NewsletterMailer, type: :mailer do
message = described_class.email_confirmation(subscriber)
expect(message.from).to eq(['[email protected]'])
- expect(message.body.encoded).to include('Second Store')
+ expect(email_body(message)).to include('Second Store')
end
end
@@ -27,13 +27,13 @@ describe Spree::NewsletterMailer, type: :mailer do
it 'builds the confirmation link from the redirect URL with the verification token appended' do
message = described_class.email_confirmation(subscriber, redirect_url: 'https://storefront.example.com/newsletter/confirm')
- expect(message.body.encoded).to include("https://storefront.example.com/newsletter/confirm?token=#{subscriber.verification_token}")
+ expect(email_body(message)).to include("https://storefront.example.com/newsletter/confirm?token=#{subscriber.verification_token}")
end
it 'merges the token into an existing query string instead of appending a new one' do
message = described_class.email_confirmation(subscriber, redirect_url: 'https://storefront.example.com/newsletter/confirm?source=footer')
- expect(message.body.encoded).to include("https://storefront.example.com/newsletter/confirm?source=footer&amp;token=#{subscriber.verification_token}")
+ expect(email_body(message)).to include("https://storefront.example.com/newsletter/confirm?source=footer&amp;token=#{subscriber.verification_token}")
end
it 'preserves a URL fragment when appending the token' do
@@ -43,7 +43,7 @@ describe Spree::NewsletterMailer, type: :mailer do
)
# The token belongs in the query string, not after the fragment.
- expect(message.body.encoded).to include(
+ expect(email_body(message)).to include(
"https://storefront.example.com/account?token=#{subscriber.verification_token}#newsletter"
)
end
@@ -53,8 +53,8 @@ describe Spree::NewsletterMailer, type: :mailer do
it 'falls back to the store storefront URL' do
message = described_class.email_confirmation(subscriber)
- expect(message.body.encoded).to include(store.storefront_url.to_s)
- expect(message.body.encoded).to include("token=#{subscriber.verification_token}")
+ expect(email_body(message)).to include(store.storefront_url.to_s)
+ expect(email_body(message)).to include("token=#{subscriber.verification_token}")
end
end
diff --git a/spree/emails/spec/mailers/spree/order_group_mailer_spec.rb b/spree/emails/spec/mailers/spree/order_group_mailer_spec.rb
index fa4f902ac1..ba0a4d11b8 100644
--- a/spree/emails/spec/mailers/spree/order_group_mailer_spec.rb
+++ b/spree/emails/spec/mailers/spree/order_group_mailer_spec.rb
@@ -144,9 +144,9 @@ describe Spree::OrderGroupMailer, type: :mailer do
it 'tells each parcel what it carries rather than what was ordered' do
text = described_class.confirm_email(group).text_part.body.to_s
- expect(text).to include('(2)')
- expect(text).to include('(1)')
- expect(text).not_to include('(3)')
+ expect(text).to include('2 x')
+ expect(text).to include('1 x')
+ expect(text).not_to include('3 x')
end
end
diff --git a/spree/emails/spec/mailers/spree/order_mailer_spec.rb b/spree/emails/spec/mailers/spree/order_mailer_spec.rb
index 8494a89e9a..398ac31c15 100644
--- a/spree/emails/spec/mailers/spree/order_mailer_spec.rb
+++ b/spree/emails/spec/mailers/spree/order_mailer_spec.rb
@@ -181,8 +181,8 @@ describe Spree::OrderMailer, type: :mailer do
body = described_class.confirm_email(order).text_part.body.to_s
expect(body).to match(/Free Shipping -\$5\.00/)
- expect(body).to match(/#{Spree.t(:shipping)}: .*\$5\.00/)
- expect(body).not_to match(/#{Spree.t(:shipping)}: .*\$0\.00/)
+ expect(body).to match(/#{Spree.t(:shipping)} .*\$5\.00/)
+ expect(body).not_to match(/#{Spree.t(:shipping)} .*\$0\.00/)
end
end
@@ -379,7 +379,7 @@ describe Spree::OrderMailer, type: :mailer do
expect(payment_link_email.from).to contain_exactly(store.mail_from_address)
expect(payment_link_email.to).to contain_exactly(order_for_payment.email)
expect(payment_link_email.subject).to eq("Payment link for order ##{order_for_payment.number}")
- expect(payment_link_email.body.to_s).to include(payment_url)
+ expect(email_body(payment_link_email)).to include(payment_url)
end
end
end
diff --git a/spree/emails/spec/mailers/spree/rendered_emails_spec.rb b/spree/emails/spec/mailers/spree/rendered_emails_spec.rb
new file mode 100644
index 0000000000..908d9f4fba
--- /dev/null
+++ b/spree/emails/spec/mailers/spree/rendered_emails_spec.rb
@@ -0,0 +1,61 @@
+require 'spec_helper'
+
+# Every email Spree ships, rendered end to end from its Liquid template with
+# customer-controlled text carrying HTML. Strict variables make a missing or
+# misspelled field fail here rather than render blank.
+describe 'rendered emails', type: :mailer do
+ let(:payload) { '<a href="https://evil.test">Click to verify</a>' }
+ let(:store) { @default_store }
+
+ let(:order) do
+ create(:completed_order_with_totals, store: store, email: '[email protected]').tap do |order|
+ order.bill_address.update_columns(first_name: payload)
+ order.line_items.first.product.update_columns(name: payload)
+ order.update_columns(po_number: payload)
+ end
+ end
+
+ let(:order_group) { create(:order_group, :with_parcels, store: store, sellers_count: 2) }
+ let(:seller) { create(:seller, store: store, name: payload, contact_email: '[email protected]') }
+ let(:company) { create(:company, store: store, name: payload) }
+
+ let(:emails) do
+ {
+ 'order confirmation' => Spree::OrderMailer.confirm_email(order),
+ 'order cancellation' => Spree::OrderMailer.cancel_email(order),
+ 'new order notification' => Spree::OrderMailer.store_owner_notification_email(order),
+ 'payment link' => Spree::OrderMailer.payment_link_email(create(:order_with_line_items, store: store).id),
+ 'purchase confirmation' => Spree::OrderGroupMailer.confirm_email(order_group),
+ 'new purchase notification' => Spree::OrderGroupMailer.store_owner_notification_email(order_group),
+ 'fulfillment' => Spree::FulfillmentMailer.fulfilled_email(create(:shipped_order, store: store).fulfillments.first),
+ 'refund' => Spree::ReturnMailer.refunded_email(create(:received_return, store: store)),
+ 'password reset' => Spree::CustomerMailer.password_reset_email(create(:user, first_name: payload), 'token', store),
+ 'data export' => Spree::CustomerMailer.data_export_email(create(:data_request, store: store)),
+ 'newsletter confirmation' => Spree::NewsletterMailer.email_confirmation(create(:newsletter_subscriber, store: store)),
+ 'company invitation' => Spree::CompanyMailer.invitation_email(create(:company_invitation, company: company)),
+ 'seller approved' => Spree::SellerMailer.approved_email(seller),
+ 'seller suspended' => Spree::SellerMailer.suspended_email(seller),
+ 'seller rejected' => Spree::SellerMailer.rejected_email(seller)
+ }
+ end
+
+ before { store.update_columns(new_order_notifications_email: '[email protected]') }
+
+ it 'renders every email completely, with a subject and both parts' do
+ emails.each do |name, message|
+ html = message.html_part.decoded
+
+ expect(message.subject).to be_present, name
+ expect(html).not_to include('{{', '{%', '<mj-'), name
+ expect(message.text_part.decoded).to be_present, name
+ end
+ end
+
+ it 'escapes customer-controlled text everywhere it appears' do
+ emails.each do |name, message|
+ expect(message.html_part.decoded).not_to include('<a href="https://evil.test">'), name
+ end
+
+ expect(emails['order confirmation'].html_part.decoded).to include('&lt;a href=&quot;https://evil.test&quot;&gt;')
+ end
+end
diff --git a/spree/emails/spec/mailers/spree/return_mailer_spec.rb b/spree/emails/spec/mailers/spree/return_mailer_spec.rb
index 98c698bb68..1aef96d08c 100644
--- a/spree/emails/spec/mailers/spree/return_mailer_spec.rb
+++ b/spree/emails/spec/mailers/spree/return_mailer_spec.rb
@@ -29,7 +29,7 @@ describe Spree::ReturnMailer, type: :mailer do
it 'names the returned items' do
variant = return_record.return_line_items.first.variant
- expect(message.body.encoded).to include(variant.product.name)
+ expect(email_body(message)).to include(variant.product.name)
end
it 'accepts an id as well as a record' do
diff --git a/spree/emails/spec/mailers/spree/seller_mailer_spec.rb b/spree/emails/spec/mailers/spree/seller_mailer_spec.rb
index 54211d9cff..7d38630fd8 100644
--- a/spree/emails/spec/mailers/spree/seller_mailer_spec.rb
+++ b/spree/emails/spec/mailers/spree/seller_mailer_spec.rb
@@ -12,11 +12,11 @@ RSpec.describe Spree::SellerMailer do
it 'tells the seller they can trade' do
expect(message.subject).to include('Sparks Marketplace')
expect(message.to).to eq(['[email protected]'])
- expect(message.body.encoded).to include('Sparks Audio')
+ expect(email_body(message)).to include('Sparks Audio')
end
it 'points them at the dashboard they sign in to' do
- expect(message.body.encoded).to include(Spree::Stores::DashboardUrl.call(store: store))
+ expect(email_body(message)).to include(Spree::Stores::DashboardUrl.call(store: store))
end
end
@@ -25,7 +25,7 @@ RSpec.describe Spree::SellerMailer do
it 'tells the seller selling has stopped, and how to reach the operator' do
expect(message.to).to eq(['[email protected]'])
- expect(message.body.encoded).to include(store.mail_from_address)
+ expect(email_body(message)).to include(store.mail_from_address)
end
# The operator's note is an internal record — a suspended seller is asked to
@@ -33,7 +33,7 @@ RSpec.describe Spree::SellerMailer do
it 'does not leak the operator note' do
seller.update!(metadata: { 'suspension_reason' => 'Counterfeit goods' })
- expect(message.body.encoded).not_to include('Counterfeit goods')
+ expect(email_body(message)).not_to include('Counterfeit goods')
end
end
@@ -42,13 +42,13 @@ RSpec.describe Spree::SellerMailer do
it 'tells the applicant they were not admitted' do
expect(message.to).to eq(['[email protected]'])
- expect(message.body.encoded).to include('Sparks Audio')
+ expect(email_body(message)).to include('Sparks Audio')
end
it 'does not leak the operator note' do
seller.update!(metadata: { 'rejection_reason' => 'Incomplete paperwork' })
- expect(message.body.encoded).not_to include('Incomplete paperwork')
+ expect(email_body(message)).not_to include('Incomplete paperwork')
end
end
diff --git a/spree/emails/spec/spec_helper.rb b/spree/emails/spec/spec_helper.rb
index 6a790aba99..373a2127d6 100644
--- a/spree/emails/spec/spec_helper.rb
+++ b/spree/emails/spec/spec_helper.rb
@@ -45,6 +45,7 @@ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
require 'spree/testing_support/i18n' if ENV['CHECK_TRANSLATIONS']
+require 'spree/testing_support/emails'
require 'spree/testing_support/factories'
require 'spree/testing_support/jobs'
require 'spree/testing_support/store'
diff --git a/spree/emails/spec/subscribers/spree/seller_lifecycle_emails_spec.rb b/spree/emails/spec/subscribers/spree/seller_lifecycle_emails_spec.rb
index ec27517a57..4b3c50891d 100644
--- a/spree/emails/spec/subscribers/spree/seller_lifecycle_emails_spec.rb
+++ b/spree/emails/spec/subscribers/spree/seller_lifecycle_emails_spec.rb
@@ -31,7 +31,7 @@ RSpec.describe 'seller lifecycle emails', events: true do
end
# The reason is an internal record, not something the seller is handed.
- expect(ActionMailer::Base.deliveries.last.body.encoded).not_to include('Counterfeit goods')
+ expect(email_body(ActionMailer::Base.deliveries.last)).not_to include('Counterfeit goods')
end
it 'tells the applicant when they are rejected' do