-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d722d07
commit 1177f9e
Showing
21 changed files
with
212 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
app/mailers/spree_dynamic_emails/spree/base_mailer_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module SpreeDynamicEmails | ||
module Spree | ||
module BaseMailerDecorator | ||
def self.prepended(base) | ||
base.before_action :ensure_default_action_mailer_url_host | ||
base.after_action :attach_metadata | ||
end | ||
|
||
private | ||
|
||
def ensure_default_action_mailer_url_host(store_url = nil) | ||
ActionMailer::Base.default_url_options ||= {} | ||
ActionMailer::Base.default_url_options[:protocol] = 'https' | ||
ActionMailer::Base.default_url_options[:host] ||= store_url | ||
end | ||
|
||
def build_template(resource, options = {}) | ||
@template = current_store.email_templates.find_by(template_name: action_name) | ||
return unless @template.present? | ||
|
||
@subject = @template.subject | ||
@body = @template.render_body(resource, options) | ||
end | ||
|
||
def attach_metadata | ||
mailer_klass = self.class.to_s | ||
mailer_action = action_name | ||
|
||
message.instance_variable_set(:@store_id, current_store.id) | ||
message.instance_variable_set(:@mailer_klass, mailer_klass) | ||
message.instance_variable_set(:@mailer_action, mailer_action) | ||
message.instance_variable_set(:@test, @test_mail) | ||
|
||
message.class.send(:attr_reader, :store_id) | ||
message.class.send(:attr_reader, :mailer_klass) | ||
message.class.send(:attr_reader, :mailer_action) | ||
message.class.send(:attr_reader, :test) | ||
end | ||
end | ||
end | ||
end | ||
|
||
::Spree::BaseMailer.prepend ::SpreeDynamicEmails::Spree::BaseMailerDecorator |
61 changes: 61 additions & 0 deletions
61
app/mailers/spree_dynamic_emails/spree/order_mailer_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
module SpreeDynamicEmails | ||
module Spree | ||
module OrderMailerDecorator | ||
def confirm_email(order, test=false, id=nil, email_to=nil) | ||
@order = order.respond_to?(:id) ? order : ::Spree::Order.find(order) | ||
@test_mail = test | ||
current_store = @order.store | ||
build_confirm_email_detail | ||
email = id.present? ? email_to : @order.email | ||
mail(to: email, from: from_address, subject: @subject, store_url: current_store.url) | ||
end | ||
|
||
def store_owner_notification_email(order, test=false, id=nil, email_to=nil) | ||
@order = order.respond_to?(:id) ? order : ::Spree::Order.find(order) | ||
@test_mail = test | ||
current_store = @order.store | ||
build_store_owner_notification_email | ||
email = id.present? ? email_to : current_store.new_order_notifications_email | ||
mail(to: email, from: from_address, subject: @subject, store_url: current_store.url) | ||
end | ||
|
||
def cancel_email(order, test=false, id=nil, email_to=nil) | ||
@order = order.respond_to?(:id) ? order : ::Spree::Order.find(order) | ||
@test_mail = test | ||
current_store = @order.store | ||
build_cancel_email_detail | ||
email = id.present? ? email_to : @order.email | ||
mail(to: email, from: from_address, subject: @subject, store_url: current_store.url) | ||
end | ||
|
||
def build_confirm_email_detail | ||
order_details | ||
end | ||
|
||
def build_cancel_email_detail | ||
order_details | ||
end | ||
|
||
def build_store_owner_notification_email | ||
order_details | ||
end | ||
|
||
private | ||
|
||
def order_details | ||
ensure_default_action_mailer_url_host(current_store.url) | ||
line_item_details = render_to_string(partial: 'spree/shared/purchased_items_table', | ||
locals: { | ||
line_items: @order.line_items, order: @order | ||
}) | ||
line_items_table = render_to_string(collection: @order.line_items, | ||
partial: 'spree/shared/purchased_items_table/line_item', as: :line_item) | ||
@body = build_template(@order, { line_item_details: line_item_details, line_items_table: line_items_table }) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Spree::OrderMailer.prepend ::SpreeDynamicEmails::Spree::OrderMailerDecorator |
28 changes: 28 additions & 0 deletions
28
app/mailers/spree_dynamic_emails/spree/reimbursement_mailer_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module SpreeDynamicEmails | ||
module Spree | ||
module ReimbursementMailerDecorator | ||
def reimbursement_email(reimbursement, test=false, id=nil, email_to=nil) | ||
@reimbursement = reimbursement.respond_to?(:id) ? reimbursement : Spree::Reimbursement.find(reimbursement) | ||
@test_mail = test | ||
@order = @reimbursement.order | ||
current_store = @reimbursement.store || Spree::Store.default | ||
reimbursement_details | ||
email = id.present? ? email_to : @order.email | ||
mail(to: email, from: current_store.mail_from_address, subject: @subject, store_url: current_store.url) | ||
end | ||
|
||
private | ||
|
||
def reimbursement_details | ||
ensure_default_action_mailer_url_host(current_store.url) | ||
reimbursement_item_details = render_to_string(partial: 'spree/reimbursement_mailer/shared/reimbursement_table', | ||
locals: { reimbursement: @reimbursement }) | ||
@body = build_template(@reimbursement, { reimbursement_item_details: reimbursement_item_details }) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Spree::ReimbursementMailer.prepend ::SpreeDynamicEmails::Spree::ReimbursementMailerDecorator |
32 changes: 32 additions & 0 deletions
32
app/mailers/spree_dynamic_emails/spree/shipment_mailer_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module SpreeDynamicEmails | ||
module Spree | ||
module ShipmentMailerDecorator | ||
def shipped_email(shipment, test=false, id=nil, email_to=nil) | ||
@shipment = shipment.respond_to?(:id) ? shipment : Spree::Shipment.find(shipment) | ||
@test_mail = test | ||
@order = @shipment.order | ||
current_store = @shipment.store | ||
shipment_details | ||
email = id.present? ? email_to : @order.email | ||
mail(to: email, from: from_address, subject: @subject, store_url: current_store.url) | ||
end | ||
|
||
private | ||
|
||
def shipment_details | ||
ensure_default_action_mailer_url_host(current_store.url) | ||
line_item_details = render_to_string(partial: 'spree/shared/purchased_items_table', | ||
locals: { | ||
line_items: @shipment.manifest.map(&:line_item), order: @shipment.order | ||
}) | ||
line_items_table = render_to_string(collection: @shipment.order.line_items, | ||
partial: 'spree/shared/purchased_items_table/line_item', as: :line_item) | ||
@body = build_template(@shipment, { line_item_details: line_item_details, line_items_table: line_items_table }) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Spree::ShipmentMailer.prepend ::SpreeDynamicEmails::Spree::ShipmentMailerDecorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.