mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-14 04:04:23 +00:00
Fix rubocop issues in mailers
This commit is contained in:
@@ -15,7 +15,9 @@ module I18nHelper
|
||||
end
|
||||
|
||||
def valid_locale(object_with_locale)
|
||||
if object_with_locale.present? && object_with_locale.locale.present? && available_locale?(object_with_locale.locale)
|
||||
if object_with_locale.present? &&
|
||||
object_with_locale.locale.present? &&
|
||||
available_locale?(object_with_locale.locale)
|
||||
object_with_locale.locale
|
||||
else
|
||||
I18n.default_locale
|
||||
|
||||
@@ -12,7 +12,8 @@ class ProducerMailer < Spree::BaseMailer
|
||||
@tax_total = tax_total_from_line_items(line_items)
|
||||
|
||||
I18n.with_locale valid_locale(@producer.owner) do
|
||||
subject = "[#{Spree::Config.site_name}] #{I18n.t('producer_mailer.order_cycle.subject', producer: producer.name)}"
|
||||
order_cycle_subject = I18n.t('producer_mailer.order_cycle.subject', producer: producer.name)
|
||||
subject = "[#{Spree::Config.site_name}] #{order_cycle_subject}"
|
||||
|
||||
return unless has_orders?(order_cycle, producer)
|
||||
mail(
|
||||
|
||||
@@ -7,48 +7,54 @@ Spree::OrderMailer.class_eval do
|
||||
def cancel_email(order, resend = false)
|
||||
@order = find_order(order)
|
||||
I18n.with_locale valid_locale(@order.user) do
|
||||
subject = (resend ? "[#{t(:resend).upcase}] " : '')
|
||||
subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{order.number}"
|
||||
mail(to: order.email, from: from_address, subject: subject)
|
||||
mail(to: order.email,
|
||||
from: from_address,
|
||||
subject: mail_subject(t('order_mailer.cancel_email.subject'), resend))
|
||||
end
|
||||
end
|
||||
|
||||
def confirm_email_for_customer(order, resend = false)
|
||||
find_order(order) # Finds an order instance from an id
|
||||
I18n.with_locale valid_locale(@order.user) do
|
||||
subject = (resend ? "[#{t(:resend).upcase}] " : '')
|
||||
subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}"
|
||||
mail(:to => @order.email,
|
||||
:from => from_address,
|
||||
:subject => subject,
|
||||
:reply_to => @order.distributor.contact.email)
|
||||
mail(to: @order.email,
|
||||
from: from_address,
|
||||
subject: mail_subject(t('order_mailer.confirm_email.subject'), resend),
|
||||
reply_to: @order.distributor.contact.email)
|
||||
end
|
||||
end
|
||||
|
||||
def confirm_email_for_shop(order, resend = false)
|
||||
find_order(order) # Finds an order instance from an id
|
||||
I18n.with_locale valid_locale(@order.user) do
|
||||
subject = (resend ? "[#{t(:resend).upcase}] " : '')
|
||||
subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}"
|
||||
mail(:to => @order.distributor.contact.email,
|
||||
:from => from_address,
|
||||
:subject => subject)
|
||||
mail(to: @order.distributor.contact.email,
|
||||
from: from_address,
|
||||
subject: mail_subject(t('order_mailer.confirm_email.subject'), resend))
|
||||
end
|
||||
end
|
||||
|
||||
def invoice_email(order, pdf)
|
||||
find_order(order) # Finds an order instance from an id
|
||||
attach_file("invoice-#{@order.number}.pdf", pdf)
|
||||
I18n.with_locale valid_locale(@order.user) do
|
||||
attachments["invoice-#{@order.number}.pdf"] = pdf if pdf.present?
|
||||
subject = "#{Spree::Config[:site_name]} #{t(:invoice)} ##{@order.number}"
|
||||
mail(:to => @order.email,
|
||||
:from => from_address,
|
||||
:subject => subject,
|
||||
:reply_to => @order.distributor.contact.email)
|
||||
mail(to: @order.email,
|
||||
from: from_address,
|
||||
subject: mail_subject(t(:invoice), false),
|
||||
reply_to: @order.distributor.contact.email)
|
||||
end
|
||||
end
|
||||
|
||||
def find_order(order)
|
||||
@order = order.respond_to?(:id) ? order : Spree::Order.find(order)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mail_subject(base_subject, resend)
|
||||
resend_prefix = (resend ? "[#{t(:resend).upcase}] " : '')
|
||||
"#{resend_prefix}#{Spree::Config[:site_name]} #{base_subject} ##{@order.number}"
|
||||
end
|
||||
|
||||
def attach_file(filename, file)
|
||||
attachments[filename] = file if file.present?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,7 +48,8 @@ class SubscriptionMailer < Spree::BaseMailer
|
||||
|
||||
def send_mail(order)
|
||||
I18n.with_locale valid_locale(order.user) do
|
||||
subject = "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{order.number}"
|
||||
confirm_email_subject = t('order_mailer.confirm_email.subject')
|
||||
subject = "#{Spree::Config[:site_name]} #{confirm_email_subject} ##{order.number}"
|
||||
mail(to: order.email,
|
||||
from: from_address,
|
||||
subject: subject,
|
||||
|
||||
Reference in New Issue
Block a user