ref: master
plugins/orders/lib/orders_plugin/mailer.rb
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
class OrdersPlugin::Mailer < Noosfero::Plugin::MailerBase include OrdersPlugin::TranslationHelper helper ApplicationHelper helper OrdersPlugin::DisplayHelper 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 sale_confirmation order profile = @profile = order.profile self.environment = profile.environment @order = order @consumer = order.consumer to = order.consumer reply_to = order.profile mail \ to: profile_recipients(to), from: environment.noreply_email, reply_to: profile_recipients(reply_to), subject: t('lib.mailer.order_was_confirmed') % {name: profile.name} end def sale_received order profile = @profile = order.profile self.environment = profile.environment @order = order @consumer = order.consumer to = @consumer reply_to = order.profile mail \ to: profile_recipients(to), from: environment.noreply_email, reply_to: profile_recipients(reply_to), subject: t('lib.mailer.order_was_received') % {name: profile.name} end def sale_cancellation order profile = @profile = order.profile self.environment = profile.environment @order = order @consumer = order.consumer @environment = profile.environment to = @consumer reply_to = order.profile mail \ to: profile_recipients(to), from: environment.noreply_email, reply_to: profile_recipients(reply_to), subject: t('lib.mailer.order_was_cancelled') % {name: profile.name} end def purchase_confirmation order profile = @profile = order.profile self.environment = profile.environment @order = order @consumer = order.consumer to = order.profile reply_to = @consumer mail \ to: profile_recipients(to), from: environment.noreply_email, reply_to: profile_recipients(reply_to), subject: t('lib.mailer.purchase_was_created') % {name: profile.name} end def purchase_received order profile = @profile = order.profile self.environment = profile.environment @order = order @consumer = order.consumer to = order.profile reply_to = @consumer mail \ to: profile_recipients(to), from: environment.noreply_email, reply_to: profile_recipients(reply_to), subject: t('lib.mailer.order_was_received') % {name: profile.name} end def purchase_cancellation order profile = @profile = order.profile self.environment = profile.environment @order = order @consumer = order.consumer @environment = profile.environment to = order.profile reply_to = @consumer mail \ to: profile_recipients(to), from: environment.noreply_email, reply_to: profile_recipients(reply_to), subject: t('lib.mailer.order_was_cancelled') % {name: profile.name} end protected def profile_recipients profile if profile.person? or profile.contact_email.present? profile.contact_email else profile.admins.map{ |p| p.contact_email } end end # for order/show_simple form def protect_against_forgery? false end helper_method :protect_against_forgery? end |