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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Refactor emails and email previews code
Damian Legawiecf62e42f9618e
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.erbindex 103b873e4e..1211f3a2c0 100644--- a/spree/core/app/views/spree/export_mailer/export_done.html.erb+++ b/spree/core/app/views/spree/export_mailer/export_done.html.erb@@ -1,13 +1,7 @@-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <h1><%= Spree.t('export_mailer.greeting', user_name: @export.user&.first_name) %></h1>- <p><%= Spree.t('export_mailer.export_done.message') %></p>- <% if spree.respond_to?(:admin_export_url) %>- <%= render 'spree/shared/mailer_button', url: spree.admin_export_url(@export, host: @current_store.formatted_url), label: @export.attachment.filename %>- <% end %>- </div>- </td>- </tr>-</table>+<%= 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 spree.respond_to?(:admin_export_url) %>+ <%= render 'spree/shared/mailer_button', url: spree.admin_export_url(@export, host: @current_store.formatted_url), label: @export.attachment.filename %>+ <% end %>+<% end %>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.erbindex d4fab36da2..640c32b56d 100644--- a/spree/core/app/views/spree/invitation_mailer/invitation_accepted.html.erb+++ b/spree/core/app/views/spree/invitation_mailer/invitation_accepted.html.erb@@ -1,10 +1,4 @@-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <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>- </div>- </td>- </tr>-</table>+<%= 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_email.html.erb b/spree/core/app/views/spree/invitation_mailer/invitation_email.html.erbindex bb93f93b76..27ec8ed9e2 100644--- a/spree/core/app/views/spree/invitation_mailer/invitation_email.html.erb+++ b/spree/core/app/views/spree/invitation_mailer/invitation_email.html.erb@@ -1,18 +1,12 @@-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <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) %>- </div>- </td>- </tr>-</table>+<%= 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/report_mailer/report_done.html.erb b/spree/core/app/views/spree/report_mailer/report_done.html.erbindex e496a5ac7a..32fcfc7c9f 100644--- a/spree/core/app/views/spree/report_mailer/report_done.html.erb+++ b/spree/core/app/views/spree/report_mailer/report_done.html.erb@@ -1,13 +1,7 @@-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <h1><%= Spree.t('report_mailer.greeting', user_name: @report.user&.first_name) %></h1>- <p><%= Spree.t('report_mailer.report_done.message') %></p>- <% if spree.respond_to?(:admin_report_url) %>- <%= render 'spree/shared/mailer_button', url: spree.admin_report_url(@report, host: @current_store.formatted_url), label: @report.attachment.filename %>- <% end %>- </div>- </td>- </tr>-</table>+<%= render layout: 'spree/shared/mailer_hero' do %>+ <h1><%= Spree.t('report_mailer.greeting', user_name: @report.user&.first_name) %></h1>+ <p><%= Spree.t('report_mailer.report_done.message') %></p>+ <% if spree.respond_to?(:admin_report_url) %>+ <%= render 'spree/shared/mailer_button', url: spree.admin_report_url(@report, host: @current_store.formatted_url), label: @report.attachment.filename %>+ <% end %>+<% end %>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.erbindex 601627689c..5b749cb738 100644--- a/spree/core/app/views/spree/shared/_base_mailer_stylesheets.html.erb+++ b/spree/core/app/views/spree/shared/_base_mailer_stylesheets.html.erb@@ -280,13 +280,6 @@text-align: center;}- .email-masthead_name {- font-size: 16px;- font-weight: 600;- color: #332C2C;- text-decoration: none;- }-/* Body ------------------------------ */.email-card {@@ -347,13 +340,9 @@text-align: center;}- .body-sub {- margin-top: 24px;- padding-top: 24px;- border-top: 1px solid #F0F0F0;- }-- /* Data table (legacy class hooks) ------------------------------ */+ /* 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 {diff --git a/spree/core/app/views/spree/shared/_mailer_hero.html.erb b/spree/core/app/views/spree/shared/_mailer_hero.html.erbnew file mode 100644index 0000000000..70c0b787f2--- /dev/null+++ b/spree/core/app/views/spree/shared/_mailer_hero.html.erb@@ -0,0 +1,12 @@+<%# 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">+ <tr>+ <td align="center">+ <div class="hero_content f-fallback">+ <%= yield %>+ </div>+ </td>+ </tr>+</table>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.erbindex 24de657d3f..e35b2ec4ff 100644--- a/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.html.erb+++ b/spree/core/app/views/spree/webhook_mailer/endpoint_disabled.html.erb@@ -1,15 +1,9 @@<%= render 'spree/shared/purchased_items_styles' %>-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <h1><%= Spree.t('webhook_mailer.endpoint_disabled.heading') %></h1>- <p><%= Spree.t('webhook_mailer.endpoint_disabled.message', endpoint_name: @endpoint.name || @endpoint.url) %></p>- </div>- </td>- </tr>-</table>+<%= 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>diff --git a/spree/core/lib/spree/core/previews/export_preview.rb b/spree/core/lib/spree/core/previews/export_preview.rbindex 1e2bb6992d..f04602fe8d 100644--- a/spree/core/lib/spree/core/previews/export_preview.rb+++ b/spree/core/lib/spree/core/previews/export_preview.rb@@ -2,6 +2,8 @@ require_relative 'preview_data'# Preview Spree export emails at /rails/mailers/spree/exportclass Spree::ExportPreview < ActionMailer::Preview+ include Spree::PreviewData::LocaleParam+def export_doneSpree::ExportMailer.export_done(export)end@@ -13,7 +15,9 @@ class Spree::ExportPreview < ActionMailer::Preview# requests a locale, always use the example so its store carries that locale.# The example is never saved, so no `export.created` side effects fire.def export- (locale.blank? && Spree::Export.last) || example_export+ return example_export if locale.present?++ Spree::Export.last || example_exportenddef example_export@@ -30,8 +34,4 @@ class Spree::ExportPreview < ActionMailer::Preview)exportend-- def locale- @params[:locale]- endenddiff --git a/spree/core/lib/spree/core/previews/invitation_preview.rb b/spree/core/lib/spree/core/previews/invitation_preview.rbindex 10d69a6170..6b95c19d12 100644--- a/spree/core/lib/spree/core/previews/invitation_preview.rb+++ b/spree/core/lib/spree/core/previews/invitation_preview.rb@@ -2,16 +2,30 @@ require_relative 'preview_data'# Preview Spree invitation emails at /rails/mailers/spree/invitationclass Spree::InvitationPreview < ActionMailer::Preview+ include Spree::PreviewData::LocaleParam+def invitation_email- Spree::InvitationMailer.invitation_email((locale.blank? && Spree::Invitation.pending.last) || example_invitation)+ Spree::InvitationMailer.invitation_email(pending_invitation)enddef invitation_accepted- Spree::InvitationMailer.invitation_accepted((locale.blank? && Spree::Invitation.accepted.last) || example_invitation(accepted: true))+ Spree::InvitationMailer.invitation_accepted(accepted_invitation)endprivate+ def pending_invitation+ return example_invitation if locale.present?++ Spree::Invitation.pending.last || example_invitation+ end++ def accepted_invitation+ return example_invitation(accepted: true) if locale.present?++ Spree::Invitation.accepted.last || example_invitation(accepted: true)+ end+# Build an in-memory invitation so the preview works on a database with no# invitations. When the preview toolbar requests a locale, its store carries# that locale. Never saved, so no records are created.@@ -30,8 +44,4 @@ class Spree::InvitationPreview < ActionMailer::Previewexpires_at: 7.days.from_now)end-- def locale- @params[:locale]- endenddiff --git a/spree/core/lib/spree/core/previews/preview_data.rb b/spree/core/lib/spree/core/previews/preview_data.rbindex 9c4db5fd78..25cb1453c9 100644--- a/spree/core/lib/spree/core/previews/preview_data.rb+++ b/spree/core/lib/spree/core/previews/preview_data.rb@@ -2,6 +2,17 @@# saved) so opening a mailer preview stays read-only.module Spreemodule PreviewData+ # Include in ActionMailer::Preview subclasses to read the preview toolbar's+ # locale dropdown (`?locale=`). The toolbar sends uppercase codes ("DE"),+ # Spree locales are lowercase.+ module LocaleParam+ private++ def locale+ @params[:locale]&.downcase+ end+ end+module_function# An admin user for previews that need `user.email` / `user.first_name`.diff --git a/spree/core/lib/spree/core/previews/report_preview.rb b/spree/core/lib/spree/core/previews/report_preview.rbindex d23d340778..8dabce73b6 100644--- a/spree/core/lib/spree/core/previews/report_preview.rb+++ b/spree/core/lib/spree/core/previews/report_preview.rb@@ -2,6 +2,8 @@ require_relative 'preview_data'# Preview Spree report emails at /rails/mailers/spree/reportclass Spree::ReportPreview < ActionMailer::Preview+ include Spree::PreviewData::LocaleParam+def report_doneSpree::ReportMailer.report_done(report)end@@ -13,7 +15,9 @@ class Spree::ReportPreview < ActionMailer::Preview# requests a locale, always use the example so its store carries that locale.# The example is never saved, so no `report.created` side effects fire.def report- (locale.blank? && Spree::Report.last) || example_report+ return example_report if locale.present?++ Spree::Report.last || example_reportenddef example_report@@ -33,8 +37,4 @@ class Spree::ReportPreview < ActionMailer::Preview)reportend-- def locale- @params[:locale]- endenddiff --git a/spree/core/lib/spree/core/previews/webhook_preview.rb b/spree/core/lib/spree/core/previews/webhook_preview.rbindex 0ddee6db8e..bbb129cd6f 100644--- a/spree/core/lib/spree/core/previews/webhook_preview.rb+++ b/spree/core/lib/spree/core/previews/webhook_preview.rb@@ -2,6 +2,8 @@ require_relative 'preview_data'# Preview Spree webhook notification emails at /rails/mailers/spree/webhookclass Spree::WebhookPreview < ActionMailer::Preview+ include Spree::PreviewData::LocaleParam+def endpoint_disabledSpree::WebhookMailer.endpoint_disabled(webhook_endpoint)end@@ -13,7 +15,9 @@ class Spree::WebhookPreview < ActionMailer::Preview# toolbar requests a locale, always use the example so its store carries that# locale. Never saved, so the admin webhook list stays clean.def webhook_endpoint- (locale.blank? && Spree::WebhookEndpoint.last) || example_endpoint+ return example_endpoint if locale.present?++ Spree::WebhookEndpoint.last || example_endpointenddef example_endpoint@@ -27,8 +31,4 @@ class Spree::WebhookPreview < ActionMailer::Previewsubscriptions: ['order.completed'])end-- def locale- @params[:locale]- endenddiff --git a/spree/emails/app/mailers/spree/order_mailer.rb b/spree/emails/app/mailers/spree/order_mailer.rbindex 5749a80375..b6d50924ef 100644--- a/spree/emails/app/mailers/spree/order_mailer.rb+++ b/spree/emails/app/mailers/spree/order_mailer.rb@@ -6,8 +6,7 @@ module Spree@order = order.respond_to?(:id) ? order : Spree::Order.find(order)current_store = @order.storewith_store_locale(current_store, @order.locale) do- subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')- subject += "#{current_store.name} #{Spree.t('order_mailer.confirm_email.subject')} ##{@order.number}"+ subject = order_email_subject(current_store, Spree.t('order_mailer.confirm_email.subject'), @order.number, resend: resend)mail(to: @order.email, from: from_address, subject: subject, store_url: current_store.storefront_url, reply_to: reply_to_address)endend@@ -25,8 +24,7 @@ module Spree@order = order.respond_to?(:id) ? order : Spree::Order.find(order)current_store = @order.storewith_store_locale(current_store, @order.locale) do- subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')- subject += "#{current_store.name} #{Spree.t('order_mailer.cancel_email.subject')} ##{@order.number}"+ subject = order_email_subject(current_store, Spree.t('order_mailer.cancel_email.subject'), @order.number, resend: resend)mail(to: @order.email, from: from_address, subject: subject, store_url: current_store.storefront_url, reply_to: reply_to_address)endenddiff --git a/spree/emails/app/mailers/spree/reimbursement_mailer.rb b/spree/emails/app/mailers/spree/reimbursement_mailer.rbindex 9036fd2eb9..405220889e 100644--- a/spree/emails/app/mailers/spree/reimbursement_mailer.rb+++ b/spree/emails/app/mailers/spree/reimbursement_mailer.rb@@ -7,8 +7,7 @@ module Spree@order = @reimbursement.ordercurrent_store = @reimbursement.store || Spree::Store.defaultwith_store_locale(current_store, @order.locale) do- subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')- subject += "#{current_store.name} #{Spree.t('reimbursement_mailer.reimbursement_email.subject')} ##{@order.number}"+ subject = order_email_subject(current_store, Spree.t('reimbursement_mailer.reimbursement_email.subject'), @order.number, resend: resend)mail(to: @order.email, from: from_address, subject: subject, store_url: current_store.storefront_url, reply_to: reply_to_address)endenddiff --git a/spree/emails/app/mailers/spree/shipment_mailer.rb b/spree/emails/app/mailers/spree/shipment_mailer.rbindex af4f3b4312..c05166914b 100644--- a/spree/emails/app/mailers/spree/shipment_mailer.rb+++ b/spree/emails/app/mailers/spree/shipment_mailer.rb@@ -8,8 +8,7 @@ module Spree@order = @shipment.ordercurrent_store = @shipment.storewith_store_locale(current_store, @order.locale) do- subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')- subject += "#{current_store.name} #{Spree.t('shipment_mailer.shipped_email.subject')} ##{@order.number}"+ subject = order_email_subject(current_store, Spree.t('shipment_mailer.shipped_email.subject'), @order.number, resend: resend)mail(to: @order.email, from: from_address, subject: subject, store_url: current_store.storefront_url, reply_to: reply_to_address)endenddiff --git a/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.html.erb b/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.html.erbindex 5c3e79378c..b8317f6c54 100644--- a/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.html.erb+++ b/spree/emails/app/views/spree/newsletter_mailer/email_confirmation.html.erb@@ -1,18 +1,12 @@-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <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>- </div>- </td>- </tr>-</table>+<%= 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/order_mailer/cancel_email.html.erb b/spree/emails/app/views/spree/order_mailer/cancel_email.html.erbindex 5f79ecba5d..8ce8a4237c 100644--- a/spree/emails/app/views/spree/order_mailer/cancel_email.html.erb+++ b/spree/emails/app/views/spree/order_mailer/cancel_email.html.erb@@ -1,22 +1,12 @@<%= render 'spree/shared/purchased_items_styles' %>-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <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>- </div>- </td>- </tr>-</table>+<%= 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 %>-<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td>- <h3 class="f-fallback"><%= Spree.t('order_mailer.cancel_email.order_summary_canceled', number: @order.number) %></h3>- <%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>- </td>- </tr>-</table>+<%= 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/confirm_email.html.erb b/spree/emails/app/views/spree/order_mailer/confirm_email.html.erbindex e46dab73cc..17c562cee1 100644--- a/spree/emails/app/views/spree/order_mailer/confirm_email.html.erb+++ b/spree/emails/app/views/spree/order_mailer/confirm_email.html.erb@@ -1,22 +1,12 @@<%= render 'spree/shared/purchased_items_styles' %>-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <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>- </div>- </td>- </tr>-</table>+<%= 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 %>-<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td>- <h3 class="f-fallback"><%= Spree.t('order_mailer.confirm_email.order_summary', number: @order.number) %></h3>- <%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>- </td>- </tr>-</table>+<%= 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/payment_link_email.html.erb b/spree/emails/app/views/spree/order_mailer/payment_link_email.html.erbindex efdc95867c..7d65425a80 100644--- 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@@ -1,17 +1,11 @@-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <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>- </div>- </td>- </tr>-</table>+<%= 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/store_owner_notification_email.html.erb b/spree/emails/app/views/spree/order_mailer/store_owner_notification_email.html.erbindex 0751cc04ca..0a1d80b20a 100644--- 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@@ -1,21 +1,11 @@<%= render 'spree/shared/purchased_items_styles' %>-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <h1><%= Spree.t('order_mailer.store_owner_notification_email.heading') %></h1>- <p><%= Spree.t('order_mailer.store_owner_notification_email.instructions') %></p>- </div>- </td>- </tr>-</table>+<%= 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 %>-<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td>- <h3 class="f-fallback"><%= Spree.t('order_mailer.store_owner_notification_email.order_summary', number: @order.number) %></h3>- <%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>- </td>- </tr>-</table>+<%= 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/reimbursement_mailer/reimbursement_email.html.erb b/spree/emails/app/views/spree/reimbursement_mailer/reimbursement_email.html.erbindex 048879b82e..4cdf1623de 100644--- a/spree/emails/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb+++ b/spree/emails/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb@@ -1,16 +1,10 @@<%= render 'spree/shared/purchased_items_styles' %>-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <h1><%= Spree.t('reimbursement_mailer.reimbursement_email.subject') %></h1>- <p class="greeting"><%= Spree.t('reimbursement_mailer.reimbursement_email.dear_customer', name: name_for(@order)) %></p>- <p><%= Spree.t('reimbursement_mailer.reimbursement_email.instructions') %></p>- </div>- </td>- </tr>-</table>+<%= render layout: 'spree/shared/mailer_hero' do %>+ <h1><%= Spree.t('reimbursement_mailer.reimbursement_email.subject') %></h1>+ <p class="greeting"><%= Spree.t('reimbursement_mailer.reimbursement_email.dear_customer', name: name_for(@order)) %></p>+ <p><%= Spree.t('reimbursement_mailer.reimbursement_email.instructions') %></p>+<% end %><table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation"><tr>@@ -21,12 +15,13 @@</tr></table>-<% if @reimbursement.return_items.exchange_requested.present? %>+<% exchange_items = @reimbursement.return_items.exchange_requested.to_a %>+<% if exchange_items.any? %><table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation"><tr><td><h3 class="f-fallback"><%= Spree.t('reimbursement_mailer.reimbursement_email.exchange_summary') %></h3>- <% @reimbursement.return_items.exchange_requested.each do |return_item| %>+ <% exchange_items.each do |return_item| %><% product_url = spree_storefront_resource_url(return_item.variant.product) %><table class="item" width="100%" cellpadding="0" cellspacing="0" role="presentation"><tr>@@ -43,7 +38,7 @@</tr></table><% end %>- <% if @reimbursement.return_items.awaiting_return.present? && Spree::Config[:expedited_exchanges] %>+ <% if @reimbursement.return_items.awaiting_return.exists? && Spree::Config[:expedited_exchanges] %><p class="sub f-fallback"><%= Spree.t('reimbursement_mailer.reimbursement_email.days_to_send', days: Spree::Config[:expedited_exchanges_days_window]) %></p><% end %></td>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.erbnew file mode 100644index 0000000000..9863dbb5dd--- /dev/null+++ b/spree/emails/app/views/spree/shared/_order_summary_section.html.erb@@ -0,0 +1,10 @@+<%# Labelled line-items + totals section shared by the order-related emails.+ Locals: heading, line_items, order. %>+<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">+ <tr>+ <td>+ <h3 class="f-fallback"><%= heading %></h3>+ <%= render 'spree/shared/purchased_items_table', line_items: line_items, order: order %>+ </td>+ </tr>+</table>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.erbindex ff2c9e8f97..88de8ef6dd 100644--- a/spree/emails/app/views/spree/shared/_purchased_items_table.html.erb+++ b/spree/emails/app/views/spree/shared/_purchased_items_table.html.erb@@ -3,52 +3,28 @@<table class="summary purchase_content" width="100%" cellpadding="0" cellspacing="0" role="presentation"><%= render 'spree/shared/purchased_items_table/subtotal', order: order %><% if order.line_item_adjustments.exists? %>- <% if order.all_adjustments.promotion.eligible.exists? %>- <% order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %>- <tr>- <td valign="top">- <span class="f-fallback"><%= Spree.t(:promotion) %></span>- <span class="f-fallback summary_sub"><%= label %></span>- </td>- <td class="summary_value" align="right" valign="top">- <span class="f-fallback"><%= Spree::Money.new(adjustments.sum(&:amount), currency: order.currency) %></span>- </td>- </tr>- <% end %>+ <% order.all_adjustments.promotion.eligible.to_a.group_by(&:label).each do |label, adjustments| %>+ <%= render 'spree/shared/purchased_items_table/summary_row',+ label: Spree.t(:promotion),+ sub: label,+ value: Spree::Money.new(adjustments.sum(&:amount), currency: order.currency) %><% end %><% end %><% order.shipments.group_by { |s| s.selected_shipping_rate&.name }.each do |name, shipments| %>- <tr>- <td valign="top">- <span class="f-fallback"><%= Spree.t(:shipping) %></span>- <% if name.present? %>- <span class="f-fallback summary_sub"><%= name %></span>- <% end %>- </td>- <td class="summary_value" align="right" valign="top">- <span class="f-fallback"><%= Spree::Money.new(shipments.sum(&:discounted_cost), currency: order.currency) %></span>- </td>- </tr>+ <%= render 'spree/shared/purchased_items_table/summary_row',+ label: Spree.t(:shipping),+ sub: name,+ value: Spree::Money.new(shipments.sum(&:discounted_cost), currency: order.currency) %><% end %><% if order.additional_tax_total != 0 %>- <tr>- <td valign="middle">- <span class="f-fallback"><%= Spree.t(:tax) %></span>- </td>- <td class="summary_value" align="right" valign="middle">- <span class="f-fallback"><%= order.display_additional_tax_total.to_html %></span>- </td>- </tr>+ <%= render 'spree/shared/purchased_items_table/summary_row',+ label: Spree.t(:tax),+ value: order.display_additional_tax_total.to_html %><% end %><% if order.gift_card_total.positive? %>- <tr>- <td valign="middle">- <span class="f-fallback"><%= Spree.t(:gift_card) %></span>- </td>- <td class="summary_value" align="right" valign="middle">- <span class="f-fallback">-<%= order.display_gift_card_total.to_html %></span>- </td>- </tr>+ <%= 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.adjustments.eligible.each do |adjustment| %><% next if (adjustment.source_type == 'Spree::TaxRate') || (adjustment.amount == 0) %>diff --git a/spree/emails/app/views/spree/shared/purchased_items_table/_adjustment.html.erb b/spree/emails/app/views/spree/shared/purchased_items_table/_adjustment.html.erbindex cb1e6ea59c..e61af50603 100644--- a/spree/emails/app/views/spree/shared/purchased_items_table/_adjustment.html.erb+++ b/spree/emails/app/views/spree/shared/purchased_items_table/_adjustment.html.erb@@ -1,8 +1,3 @@-<tr>- <td valign="middle">- <span class="f-fallback"><%= adjustment.label %></span>- </td>- <td class="summary_value" align="right" valign="middle">- <span class="f-fallback"><%= Spree::Money.new(adjustment.amount, currency: order.currency) %></span>- </td>-</tr>+<%= render 'spree/shared/purchased_items_table/summary_row',+ label: adjustment.label,+ value: Spree::Money.new(adjustment.amount, currency: order.currency) %>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.erbindex 12bd1bd28b..615ea0d23e 100644--- 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@@ -1,8 +1,3 @@-<tr>- <td valign="middle">- <span class="f-fallback"><%= Spree.t('order_mailer.subtotal') %></span>- </td>- <td class="summary_value" align="right" valign="middle">- <span class="f-fallback"><%= order.display_item_total %></span>- </td>-</tr>+<%= 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.erbnew file mode 100644index 0000000000..badf9ce92b--- /dev/null+++ b/spree/emails/app/views/spree/shared/purchased_items_table/_summary_row.html.erb@@ -0,0 +1,14 @@+<%# 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 %></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.erbindex fe073b2294..c2cf68ac1b 100644--- 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@@ -1,8 +1,4 @@-<tr class="summary_total">- <td valign="middle">- <span class="f-fallback"><%= Spree.t('order_mailer.total') %></span>- </td>- <td class="summary_value" align="right" valign="middle">- <span class="f-fallback"><%= order.display_total_minus_store_credits %></span>- </td>-</tr>+<%= 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/app/views/spree/shipment_mailer/shipped_email.html.erb b/spree/emails/app/views/spree/shipment_mailer/shipped_email.html.erbindex 4d4237941d..7a705260e7 100644--- a/spree/emails/app/views/spree/shipment_mailer/shipped_email.html.erb+++ b/spree/emails/app/views/spree/shipment_mailer/shipped_email.html.erb@@ -1,29 +1,19 @@<%= render 'spree/shared/purchased_items_styles' %>-<table class="hero" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td align="center">- <div class="hero_content f-fallback">- <h1><%= Spree.t('shipment_mailer.shipped_email.subject') %></h1>- <p class="greeting"><%= Spree.t('shipment_mailer.shipped_email.dear_customer', name: name_for(@shipment.order)) %></p>- <p><%= Spree.t('shipment_mailer.shipped_email.instructions', number: @shipment.order.number) %></p>- <p><%= Spree.t('shipment_mailer.shipped_email.shipping_method', shipping_method: @shipment.shipping_method.name) %></p>- <% if @shipment.tracking %>- <p><%= Spree.t('shipment_mailer.shipped_email.track_information', tracking: @shipment.tracking) %></p>- <% end %>- <% if @shipment.tracking_url %>- <p><%= Spree.t('shipment_mailer.shipped_email.track_link', url: shipment_tracking_link_to(shipment: @shipment)).html_safe %></p>- <% end %>- </div>- </td>- </tr>-</table>+<%= render layout: 'spree/shared/mailer_hero' do %>+ <h1><%= Spree.t('shipment_mailer.shipped_email.subject') %></h1>+ <p class="greeting"><%= Spree.t('shipment_mailer.shipped_email.dear_customer', name: name_for(@shipment.order)) %></p>+ <p><%= Spree.t('shipment_mailer.shipped_email.instructions', number: @shipment.order.number) %></p>+ <p><%= Spree.t('shipment_mailer.shipped_email.shipping_method', shipping_method: @shipment.shipping_method.name) %></p>+ <% if @shipment.tracking %>+ <p><%= Spree.t('shipment_mailer.shipped_email.track_information', tracking: @shipment.tracking) %></p>+ <% end %>+ <% if @shipment.tracking_url %>+ <p><%= Spree.t('shipment_mailer.shipped_email.track_link', url: shipment_tracking_link_to(shipment: @shipment)).html_safe %></p>+ <% end %>+<% end %>-<table class="section" width="100%" cellpadding="0" cellspacing="0" role="presentation">- <tr>- <td>- <h3 class="f-fallback"><%= Spree.t('shipment_mailer.shipped_email.shipment_summary') %></h3>- <%= render 'spree/shared/purchased_items_table', line_items: @shipment.manifest.map(&:line_item), order: @shipment.order %>- </td>- </tr>-</table>+<%= render 'spree/shared/order_summary_section',+ heading: Spree.t('shipment_mailer.shipped_email.shipment_summary'),+ line_items: @shipment.manifest.map(&:line_item),+ order: @shipment.order %>diff --git a/spree/emails/lib/spree/emails/previews/newsletter_preview.rb b/spree/emails/lib/spree/emails/previews/newsletter_preview.rbindex 4cb76edf64..4a4763b427 100644--- a/spree/emails/lib/spree/emails/previews/newsletter_preview.rb+++ b/spree/emails/lib/spree/emails/previews/newsletter_preview.rb@@ -2,13 +2,20 @@ require 'spree/core/previews/preview_data'# Preview Spree newsletter emails at /rails/mailers/spree/newsletterclass Spree::NewsletterPreview < ActionMailer::Preview+ include Spree::PreviewData::LocaleParam+def email_confirmation- subscriber = (locale.blank? && Spree::NewsletterSubscriber.unverified.last) || example_subscriberSpree::NewsletterMailer.email_confirmation(subscriber)endprivate+ def subscriber+ return example_subscriber if locale.present?++ Spree::NewsletterSubscriber.unverified.last || example_subscriber+ end+# Build an in-memory subscriber so the preview works on a database with no# newsletter subscribers. When the preview toolbar requests a locale, its# store carries that locale. Never saved, so no records are created.@@ -20,8 +27,4 @@ class Spree::NewsletterPreview < ActionMailer::Previewsubscriber.verification_token ||= 'preview-token'subscriberend-- def locale- @params[:locale]- endenddiff --git a/spree/emails/lib/spree/emails/previews/order_preview.rb b/spree/emails/lib/spree/emails/previews/order_preview.rbindex f1ab8fbfa0..9af3eff8b8 100644--- a/spree/emails/lib/spree/emails/previews/order_preview.rb+++ b/spree/emails/lib/spree/emails/previews/order_preview.rb@@ -1,5 +1,9 @@+require 'spree/core/previews/preview_data'+# Preview Spree order emails at /rails/mailers/spree/orderclass Spree::OrderPreview < ActionMailer::Preview+ include Spree::PreviewData::LocaleParam+def confirm_emailSpree::OrderMailer.confirm_email(order)end@@ -21,8 +25,4 @@ class Spree::OrderPreview < ActionMailer::Previeworder.locale = locale if order && locale.present?orderend-- def locale- @params[:locale]&.downcase- endenddiff --git a/spree/emails/lib/spree/emails/previews/reimbursement_preview.rb b/spree/emails/lib/spree/emails/previews/reimbursement_preview.rbindex 006f6c9c23..228012a8d6 100644--- a/spree/emails/lib/spree/emails/previews/reimbursement_preview.rb+++ b/spree/emails/lib/spree/emails/previews/reimbursement_preview.rb@@ -1,14 +1,12 @@+require 'spree/core/previews/preview_data'+# Preview Spree reimbursement emails at /rails/mailers/spree/reimbursementclass Spree::ReimbursementPreview < ActionMailer::Preview+ include Spree::PreviewData::LocaleParam+def reimbursement_emailreimbursement = Spree::Reimbursement.lastreimbursement.order.locale = locale if reimbursement && locale.present?Spree::ReimbursementMailer.reimbursement_email(reimbursement)end-- private-- def locale- @params[:locale]&.downcase- endenddiff --git a/spree/emails/lib/spree/emails/previews/shipment_preview.rb b/spree/emails/lib/spree/emails/previews/shipment_preview.rbindex f2b03fc093..ea55e1b8ed 100644--- a/spree/emails/lib/spree/emails/previews/shipment_preview.rb+++ b/spree/emails/lib/spree/emails/previews/shipment_preview.rb@@ -1,14 +1,12 @@+require 'spree/core/previews/preview_data'+# Preview Spree shipment emails at /rails/mailers/spree/shipmentclass Spree::ShipmentPreview < ActionMailer::Preview+ include Spree::PreviewData::LocaleParam+def shipped_emailshipment = Spree::Shipment.shipped.lastshipment.order.locale = locale if shipment && locale.present?Spree::ShipmentMailer.shipped_email(shipment)end-- private-- def locale- @params[:locale]&.downcase- endend