mailer.rb
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class OrdersPlugin::Mailer < Noosfero::Plugin::MailerBase
include OrdersPlugin::TranslationHelper
helper ApplicationHelper
helper OrdersPlugin::DisplayHelper
helper OrdersPlugin::DateHelper
helper OrdersPlugin::TranslationHelper
attr_accessor :environment
attr_accessor :profile
def message_to_consumer profile, consumer, subject, message = nil, options = {}
@consumer = consumer
message_to_actor profile, consumer, subject, message, options
end
def message_to_supplier profile, supplier, subject, message = nil, options = {}
@supplier = supplier
message_to_actor profile, supplier, subject, message, options
end
def message_to_actor profile, actor, subject, message = nil, options = {}
self.environment = profile.environment
@profile = profile
@message = message
@order = options[:order]
@include_order = options[:include_order] == '1'
mail from: environment.noreply_email,
to: profile_recipients(actor),
reply_to: profile_recipients(@profile),
subject: t('lib.mailer.profile_subject') % {profile: profile.name, subject: subject}
end
def message_to_admins profile, member, subject, message
self.environment = profile.environment
@profile = profile
@member = member
@message = message
mail from: environment.noreply_email,
to: profile_recipients(@profile),
reply_to: profile_recipients(@member),
subject: t('lib.mailer.profile_subject') % {profile: profile.name, subject: subject}
end
def order_confirmation order
profile = @profile = order.profile
self.environment = profile.environment
@order = order
@consumer = order.consumer
mail to: profile_recipients(order.consumer),
from: environment.noreply_email,
reply_to: profile_recipients(profile),
subject: t('lib.mailer.order_was_confirmed') % {name: profile.name}
end
def order_cancellation order
profile = @profile = order.profile
self.environment = profile.environment
@order = order
@consumer = order.consumer
@environment = profile.environment
mail to: profile_recipients(order.consumer),
from: environment.noreply_email,
reply_to: profile_recipients(profile),
subject: t('lib.mailer.order_was_cancelled') % {name: profile.name}
end
protected
def profile_recipients profile
if profile.person?
profile.contact_email
elsif profile.contact_email.present?
profile.contact_email
else
profile.admins.map{ |p| p.contact_email }
end
end
end