From ad8b120e4869c53a0ec04abff8bdd63de4191d7c Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 30 Aug 2018 02:58:02 +0800 Subject: [PATCH] Extract format for order cycle closing in emails Using a helper for this, but this can be changed to look up a translation key. --- app/helpers/shop_mail_helper.rb | 8 ++++++++ app/mailers/subscription_mailer.rb | 1 + .../subscription_mailer/confirmation_email.html.haml | 2 +- .../subscription_mailer/failed_payment_email.html.haml | 2 +- app/views/subscription_mailer/placement_email.html.haml | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 app/helpers/shop_mail_helper.rb diff --git a/app/helpers/shop_mail_helper.rb b/app/helpers/shop_mail_helper.rb new file mode 100644 index 0000000000..ad97f878bb --- /dev/null +++ b/app/helpers/shop_mail_helper.rb @@ -0,0 +1,8 @@ +module ShopMailHelper + # Long datetime format string used in emails to customers + # + # Example: "Fri Aug 31 @ 11:00PM" + def mail_long_datetime_format + "%a %b %d @ %l:%M%p" + end +end diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index bcb0448214..426d94f847 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -1,5 +1,6 @@ class SubscriptionMailer < Spree::BaseMailer helper CheckoutHelper + helper ShopMailHelper def confirmation_email(order) @type = 'confirmation' diff --git a/app/views/subscription_mailer/confirmation_email.html.haml b/app/views/subscription_mailer/confirmation_email.html.haml index 2001c5ba0e..befb315db4 100644 --- a/app/views/subscription_mailer/confirmation_email.html.haml +++ b/app/views/subscription_mailer/confirmation_email.html.haml @@ -4,7 +4,7 @@ %p.callout = t("email_so_confirmation_explainer_html") = t("email_so_edit_false_html", - orders_close_at: l(@order.order_cycle.orders_close_at, format: "%a %b %d @ %l:%M%p"), + orders_close_at: l(@order.order_cycle.orders_close_at, format: mail_long_datetime_format), order_url: spree.order_url(@order)) = t("email_so_contact_distributor_html", distributor: @order.distributor.name, email: @order.distributor.contact.email) diff --git a/app/views/subscription_mailer/failed_payment_email.html.haml b/app/views/subscription_mailer/failed_payment_email.html.haml index b8728a3319..72715a929d 100644 --- a/app/views/subscription_mailer/failed_payment_email.html.haml +++ b/app/views/subscription_mailer/failed_payment_email.html.haml @@ -3,7 +3,7 @@ %p.callout = t("email_so_failed_payment_explainer_html", distributor: @order.distributor.name) = t("email_so_edit_false_html", - orders_close_at: l(@order.order_cycle.orders_close_at, format: "%a %b %d @ %l:%M%p"), + orders_close_at: l(@order.order_cycle.orders_close_at, format: mail_long_datetime_format), order_url: spree.order_url(@order)) = t("email_so_contact_distributor_html", distributor: @order.distributor.name, email: @order.distributor.contact.email) diff --git a/app/views/subscription_mailer/placement_email.html.haml b/app/views/subscription_mailer/placement_email.html.haml index 78f107a76a..3a12a296e9 100644 --- a/app/views/subscription_mailer/placement_email.html.haml +++ b/app/views/subscription_mailer/placement_email.html.haml @@ -5,7 +5,7 @@ = t("email_so_placement_explainer_html") - allow_changes = !!@order.distributor.allow_order_changes? = t("email_so_edit_#{allow_changes}_html", - orders_close_at: l(@order.order_cycle.orders_close_at, format: "%a %b %d @ %l:%M%p"), + orders_close_at: l(@order.order_cycle.orders_close_at, format: mail_long_datetime_format), order_url: spree.order_url(@order)) = t("email_so_contact_distributor_html", distributor: @order.distributor.name, email: @order.distributor.contact.email)