From 626a12d8c55f80bee4497b7d08f707729d2918b2 Mon Sep 17 00:00:00 2001 From: Vishal Date: Thu, 10 Aug 2023 18:43:22 +0530 Subject: [PATCH 1/2] Spree Dynamic email compatible with spree 4.6 --- app/mailers/spree/custom_mailer.rb | 2 +- app/mailers/spree/order_mailer.rb | 6 +- app/mailers/spree/reimbursement_mailer.rb | 2 +- .../spree/return_authorization_mailer.rb | 2 +- app/mailers/spree/shipment_mailer.rb | 2 +- app/models/spree/email_template.rb | 2 +- .../spree/admin/add_mail_tab_to_main_menu.rb | 12 --- .../spree/admin/shared/_main_menu.html.erb | 99 +++++++++++++++++++ .../admin/shared/sub_menu/_template.html.erb | 2 +- spree_dynamic_emails.gemspec | 2 +- 10 files changed, 109 insertions(+), 22 deletions(-) delete mode 100644 app/overrides/spree/admin/add_mail_tab_to_main_menu.rb create mode 100644 app/views/spree/admin/shared/_main_menu.html.erb diff --git a/app/mailers/spree/custom_mailer.rb b/app/mailers/spree/custom_mailer.rb index 97fa8bb..11a7120 100644 --- a/app/mailers/spree/custom_mailer.rb +++ b/app/mailers/spree/custom_mailer.rb @@ -2,7 +2,7 @@ module Spree class CustomMailer < ::Spree::BaseMailer - def custom_email(resend = false, test: false, id: nil, email_to: nil) + def custom_email(record=nil, test=false, id=nil, email_to=nil) @test_mail = test find_template(id) email = email_to diff --git a/app/mailers/spree/order_mailer.rb b/app/mailers/spree/order_mailer.rb index ddaf361..e54904f 100644 --- a/app/mailers/spree/order_mailer.rb +++ b/app/mailers/spree/order_mailer.rb @@ -2,7 +2,7 @@ module Spree class OrderMailer < ::Spree::BaseMailer - def confirm_email(order, resend = false, test: false, id: nil, email_to: nil) + 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 @@ -11,7 +11,7 @@ def confirm_email(order, resend = false, test: false, id: nil, email_to: nil) 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) + 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 @@ -20,7 +20,7 @@ def store_owner_notification_email(order, test: false, id: nil, email_to: nil) mail(to: email, from: from_address, subject: @subject, store_url: current_store.url) end - def cancel_email(order, resend = false, test: false, id: nil, email_to: nil) + 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 diff --git a/app/mailers/spree/reimbursement_mailer.rb b/app/mailers/spree/reimbursement_mailer.rb index d9d061f..44e5439 100644 --- a/app/mailers/spree/reimbursement_mailer.rb +++ b/app/mailers/spree/reimbursement_mailer.rb @@ -2,7 +2,7 @@ module Spree class ReimbursementMailer < BaseMailer - def reimbursement_email(reimbursement, resend = false, test: false, id: nil, email_to: nil) + 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 diff --git a/app/mailers/spree/return_authorization_mailer.rb b/app/mailers/spree/return_authorization_mailer.rb index 1746ebd..55168dc 100644 --- a/app/mailers/spree/return_authorization_mailer.rb +++ b/app/mailers/spree/return_authorization_mailer.rb @@ -2,7 +2,7 @@ module Spree class ReturnAuthorizationMailer < BaseMailer - def return_authorization_email(return_authorization, test = false, id: nil, email_to: nil) + def return_authorization_email(return_authorization, test= false, id= nil, email_to=nil) @return_authorization = return_authorization.respond_to?(:id) ? return_authorization : Spree::ReturnAuthorization.find(return_authorization) @test_mail = test @order = @return_authorization.order diff --git a/app/mailers/spree/shipment_mailer.rb b/app/mailers/spree/shipment_mailer.rb index 73fa394..61c8113 100644 --- a/app/mailers/spree/shipment_mailer.rb +++ b/app/mailers/spree/shipment_mailer.rb @@ -2,7 +2,7 @@ module Spree class ShipmentMailer < BaseMailer - def shipped_email(shipment, resend = false, test: false, id: nil, email_to: nil) + 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 diff --git a/app/models/spree/email_template.rb b/app/models/spree/email_template.rb index 391f267..48797af 100644 --- a/app/models/spree/email_template.rb +++ b/app/models/spree/email_template.rb @@ -18,7 +18,7 @@ def render_body(resource, options) end def send_mail - mailer_class.constantize.send(template_name, record, test: true, id: id).deliver_now + mailer_class.constantize.send(template_name, record, true, id, nil).deliver_now end def record diff --git a/app/overrides/spree/admin/add_mail_tab_to_main_menu.rb b/app/overrides/spree/admin/add_mail_tab_to_main_menu.rb deleted file mode 100644 index c5baea7..0000000 --- a/app/overrides/spree/admin/add_mail_tab_to_main_menu.rb +++ /dev/null @@ -1,12 +0,0 @@ -Deface::Override.new( - virtual_path: 'spree/admin/shared/_main_menu', - name: 'add_mail_tab_to_main_menu', - insert_before: "ul#sidebarConfiguration", - text: <<-HTML - <% if can? :admin, current_store %> - - <% end %> - HTML -) diff --git a/app/views/spree/admin/shared/_main_menu.html.erb b/app/views/spree/admin/shared/_main_menu.html.erb new file mode 100644 index 0000000..fc079e3 --- /dev/null +++ b/app/views/spree/admin/shared/_main_menu.html.erb @@ -0,0 +1,99 @@ + diff --git a/app/views/spree/admin/shared/sub_menu/_template.html.erb b/app/views/spree/admin/shared/sub_menu/_template.html.erb index 5cbc105..ea20d2e 100644 --- a/app/views/spree/admin/shared/sub_menu/_template.html.erb +++ b/app/views/spree/admin/shared/sub_menu/_template.html.erb @@ -1,4 +1,4 @@ -