Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spree 2 Upgrade - MailMethod - Fixed bug on order_mailer_decorator (only visible in spree 2) #2587

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions app/mailers/spree/order_mailer_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,42 @@
helper CheckoutHelper
helper SpreeCurrencyHelper

def cancel_email(order, resend = false)
@order = find_order(order)
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)
end

def confirm_email_for_customer(order, resend = false)
find_order(order) # Finds an order instance from an id
subject = (resend ? "[#{t(:resend).upcase}] " : '')
subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}"
def confirm_email_for_customer(order_or_order_id, resend = false)
@order = find_order(order_or_order_id)
subject = build_subject(t('order_mailer.confirm_email.subject'), resend)
mail(:to => @order.email,
:from => from_address,
:subject => subject,
:reply_to => @order.distributor.contact.email)
end

def confirm_email_for_shop(order, resend = false)
find_order(order) # Finds an order instance from an id
subject = (resend ? "[#{t(:resend).upcase}] " : '')
subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}"
def confirm_email_for_shop(order_or_order_id, resend = false)
@order = find_order(order_or_order_id)
subject = build_subject(t('order_mailer.confirm_email.subject'), resend)
mail(:to => @order.distributor.contact.email,
:from => from_address,
:subject => subject)
end

def invoice_email(order, pdf)
find_order(order) # Finds an order instance from an id
def invoice_email(order_or_order_id, pdf)
@order = find_order(order_or_order_id)
subject = build_subject(t(:invoice))
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)
end

def find_order(order)
@order = order.respond_to?(:id) ? order : Spree::Order.find(order)
private

# Finds an order instance from an order or from an order id
def find_order(order_or_order_id)
order_or_order_id.respond_to?(:id) ? order_or_order_id : Spree::Order.find(order_or_order_id)
end

def build_subject( subject_text, resend = false )
subject = (resend ? "[#{t(:resend).upcase}] " : "")
subject += "#{Spree::Config[:site_name]} #{subject_text} ##{@order.number}"
end
end
2 changes: 0 additions & 2 deletions spec/mailers/order_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'spec_helper'

describe Spree::OrderMailer do
let!(:mail_method) { create(:mail_method, preferred_mails_from: '[email protected]') }

describe "order confimation" do
after do
ActionMailer::Base.deliveries.clear
Expand Down
2 changes: 0 additions & 2 deletions spec/mailers/subscription_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
describe SubscriptionMailer do
include ActionView::Helpers::SanitizeHelper

let!(:mail_method) { create(:mail_method, preferred_mails_from: '[email protected]') }

describe "order placement" do
let(:subscription) { create(:subscription, with_items: true) }
let(:proxy_order) { create(:proxy_order, subscription: subscription) }
Expand Down