spree_emails 4.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/LICENSE +26 -0
  4. data/Rakefile +15 -0
  5. data/app/assets/config/spree_emails_manifest.js +1 -0
  6. data/app/assets/images/logo/spree_50.png +0 -0
  7. data/app/assets/images/noimage/mini.png +0 -0
  8. data/app/assets/images/noimage/noimage/large.png +0 -0
  9. data/app/assets/images/noimage/noimage/mini.png +0 -0
  10. data/app/assets/images/noimage/noimage/product.png +0 -0
  11. data/app/assets/images/noimage/noimage/small.png +0 -0
  12. data/app/assets/images/noimage/small.png +0 -0
  13. data/app/helpers/spree/mail_helper.rb +34 -0
  14. data/app/mailers/spree/base_mailer.rb +46 -0
  15. data/app/mailers/spree/order_mailer.rb +26 -0
  16. data/app/mailers/spree/reimbursement_mailer.rb +12 -0
  17. data/app/mailers/spree/shipment_mailer.rb +12 -0
  18. data/app/mailers/spree/test_mailer.rb +8 -0
  19. data/app/models/spree/emails/order_decorator.rb +28 -0
  20. data/app/models/spree/emails/reimbursement_decorator.rb +11 -0
  21. data/app/models/spree/emails/shipment_handler_decorator.rb +13 -0
  22. data/app/views/layouts/spree/base_mailer.html.erb +46 -0
  23. data/app/views/spree/order_mailer/cancel_email.html.erb +24 -0
  24. data/app/views/spree/order_mailer/cancel_email.text.erb +12 -0
  25. data/app/views/spree/order_mailer/confirm_email.html.erb +23 -0
  26. data/app/views/spree/order_mailer/confirm_email.text.erb +12 -0
  27. data/app/views/spree/order_mailer/store_owner_notification_email.html.erb +23 -0
  28. data/app/views/spree/order_mailer/store_owner_notification_email.text.erb +12 -0
  29. data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +48 -0
  30. data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +24 -0
  31. data/app/views/spree/shared/_base_mailer_footer.html.erb +12 -0
  32. data/app/views/spree/shared/_base_mailer_header.html.erb +8 -0
  33. data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +456 -0
  34. data/app/views/spree/shared/_mailer_line_item.html.erb +12 -0
  35. data/app/views/spree/shared/_purchased_items_table.html.erb +64 -0
  36. data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +13 -0
  37. data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +19 -0
  38. data/app/views/spree/shared/purchased_items_table/_subtotal.html.erb +13 -0
  39. data/app/views/spree/shared/purchased_items_table/_total.html.erb +13 -0
  40. data/app/views/spree/shipment_mailer/shipped_email.html.erb +36 -0
  41. data/app/views/spree/shipment_mailer/shipped_email.text.erb +17 -0
  42. data/app/views/spree/test_mailer/test_email.html.erb +40 -0
  43. data/app/views/spree/test_mailer/test_email.text.erb +4 -0
  44. data/config/initializers/assets.rb +1 -0
  45. data/lib/generators/spree/emails/install/install_generator.rb +27 -0
  46. data/lib/generators/spree/emails/install/templates/mailers/previews/order_preview.rb +13 -0
  47. data/lib/generators/spree/emails/install/templates/mailers/previews/reimbursement_preview.rb +5 -0
  48. data/lib/generators/spree/emails/install/templates/mailers/previews/shipment_preview.rb +5 -0
  49. data/lib/generators/spree/emails/install/templates/mailers/previews/user_preview.rb +11 -0
  50. data/lib/spree/emails.rb +12 -0
  51. data/lib/spree/emails/engine.rb +18 -0
  52. data/lib/spree_emails.rb +1 -0
  53. data/lib/tasks/email.rake +10 -0
  54. data/script/rails +9 -0
  55. data/spree_emails.gemspec +34 -0
  56. metadata +158 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2d8ffc8031b0c951950125c2f3aefeea1935083cd3cfefed6b7967c5db9d4af6
4
+ data.tar.gz: a2dcc1259ab714411bb1784cb4e959bb6009f422b8f753ed459c11e321394db3
5
+ SHA512:
6
+ metadata.gz: 20c78dc6b9e58336817835c428bb17d6a2be1f1e694324f8b705d409b38867ee2f316038cb155cb20235e7c2c01246982b1d5363714629d07b83157a9fc328ab
7
+ data.tar.gz: c558ef5582a59dc7c8a93bdafd214496770477cf41146de69b1a86980dceedff0d00796225432356fa691480f97ea5c02e36a5451ae3e3e02ef8df0499fd36a4
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ eval_gemfile('../common_spree_dependencies.rb')
2
+
3
+ gem 'spree_core', path: '../core'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2007-2021, Spree Commerce, Inc., Spark Solutions Sp. z o.o. and other contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task default: :spec
10
+
11
+ desc "Generates a dummy app for testing"
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'spree/emails'
14
+ Rake::Task['common:test_app'].invoke
15
+ end
@@ -0,0 +1 @@
1
+ //= link_tree ../images
Binary file
Binary file
Binary file
@@ -0,0 +1,34 @@
1
+ module Spree
2
+ module MailHelper
3
+ include BaseHelper
4
+
5
+ def variant_image_url(variant)
6
+ image = default_image_for_product_or_variant(variant)
7
+ image ? main_app.url_for(image.url(:small)) : 'noimage/small.png'
8
+ end
9
+
10
+ def name_for(order)
11
+ order.name || Spree.t('customer')
12
+ end
13
+
14
+ def store_logo
15
+ @store_logo ||= current_store&.mailer_logo || current_store&.logo
16
+ end
17
+
18
+ def default_logo
19
+ ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
20
+ `MailHelper#default_logo` is deprecated and will be removed in Spree 5.0.
21
+ Please upload a Store logo instead
22
+ DEPRECATION
23
+
24
+ Spree::Config.mailer_logo || Spree::Config.logo
25
+ end
26
+
27
+ def logo_path
28
+ return default_logo unless store_logo.attached?
29
+ return main_app.url_for(store_logo.variant(resize: '244x104>')) if store_logo.variable?
30
+
31
+ return main_app.url_for(store_logo) if store_logo.image?
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ module Spree
2
+ class BaseMailer < ActionMailer::Base
3
+ helper Spree::MailHelper
4
+
5
+ def current_store
6
+ @current_store ||= @order&.store.presence || Spree::Dependencies.current_store_finder.constantize.new.execute
7
+ end
8
+ helper_method :current_store
9
+
10
+ def from_address
11
+ current_store.mail_from_address
12
+ end
13
+
14
+ def money(amount, currency = nil)
15
+ currency ||= current_store.default_currency
16
+ Spree::Money.new(amount, currency: currency).to_s
17
+ end
18
+ helper_method :money
19
+
20
+ def frontend_available?
21
+ Spree::Core::Engine.frontend_available?
22
+ end
23
+ helper_method :frontend_available?
24
+
25
+ def mail(headers = {}, &block)
26
+ ensure_default_action_mailer_url_host(headers[:store_url])
27
+ set_email_locale
28
+ super if Spree::Config[:send_core_emails]
29
+ end
30
+
31
+ private
32
+
33
+ # this ensures that ActionMailer::Base.default_url_options[:host] is always set
34
+ # this is only a fail-safe solution if developer didn't set this in environment files
35
+ # http://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-in-action-mailer-views
36
+ def ensure_default_action_mailer_url_host(store_url = nil)
37
+ ActionMailer::Base.default_url_options ||= {}
38
+ ActionMailer::Base.default_url_options[:host] ||= store_url || current_store.url
39
+ end
40
+
41
+ def set_email_locale
42
+ locale = @order&.store&.default_locale || current_store&.default_locale
43
+ I18n.locale = locale if locale.present?
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ module Spree
2
+ class OrderMailer < BaseMailer
3
+ def confirm_email(order, resend = false)
4
+ @order = order.respond_to?(:id) ? order : Spree::Order.find(order)
5
+ current_store = @order.store
6
+ subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
7
+ subject += "#{current_store.name} #{Spree.t('order_mailer.confirm_email.subject')} ##{@order.number}"
8
+ mail(to: @order.email, from: from_address, subject: subject, store_url: current_store.url)
9
+ end
10
+
11
+ def store_owner_notification_email(order)
12
+ @order = order.respond_to?(:id) ? order : Spree::Order.find(order)
13
+ current_store = @order.store
14
+ subject = Spree.t('order_mailer.store_owner_notification_email.subject', store_name: current_store.name)
15
+ mail(to: current_store.new_order_notifications_email, from: from_address, subject: subject, store_url: current_store.url)
16
+ end
17
+
18
+ def cancel_email(order, resend = false)
19
+ @order = order.respond_to?(:id) ? order : Spree::Order.find(order)
20
+ current_store = @order.store
21
+ subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
22
+ subject += "#{current_store.name} #{Spree.t('order_mailer.cancel_email.subject')} ##{@order.number}"
23
+ mail(to: @order.email, from: from_address, subject: subject, store_url: current_store.url)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module Spree
2
+ class ReimbursementMailer < BaseMailer
3
+ def reimbursement_email(reimbursement, resend = false)
4
+ @reimbursement = reimbursement.respond_to?(:id) ? reimbursement : Spree::Reimbursement.find(reimbursement)
5
+ @order = @reimbursement.order
6
+ current_store = @reimbursement.store || Spree::Store.default
7
+ subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
8
+ subject += "#{current_store.name} #{Spree.t('reimbursement_mailer.reimbursement_email.subject')} ##{@order.number}"
9
+ mail(to: @order.email, from: current_store.mail_from_address, subject: subject, store_url: current_store.url)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Spree
2
+ class ShipmentMailer < BaseMailer
3
+ def shipped_email(shipment, resend = false)
4
+ @shipment = shipment.respond_to?(:id) ? shipment : Spree::Shipment.find(shipment)
5
+ @order = @shipment.order
6
+ current_store = @shipment.store
7
+ subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
8
+ subject += "#{current_store.name} #{Spree.t('shipment_mailer.shipped_email.subject')} ##{@order.number}"
9
+ mail(to: @order.email, from: from_address, subject: subject, store_url: current_store.url)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ module Spree
2
+ class TestMailer < BaseMailer
3
+ def test_email(email)
4
+ subject = "#{Spree::Store.default.name} #{Spree.t('test_mailer.test_email.subject')}"
5
+ mail(to: email, from: from_address, subject: subject)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,28 @@
1
+ module Spree
2
+ module Emails
3
+ module OrderDecorator
4
+ def deliver_order_confirmation_email
5
+ OrderMailer.confirm_email(id).deliver_later
6
+ update_column(:confirmation_delivered, true)
7
+ end
8
+
9
+ # Returns true if:
10
+ # 1. an email address is set for new order notifications AND
11
+ # 2. no notification for this order has been sent yet.
12
+ def deliver_store_owner_order_notification_email?
13
+ store.new_order_notifications_email.present? && !store_owner_notification_delivered?
14
+ end
15
+
16
+ def deliver_store_owner_order_notification_email
17
+ OrderMailer.store_owner_notification_email(id).deliver_later
18
+ update_column(:store_owner_notification_delivered, true)
19
+ end
20
+
21
+ def send_cancel_email
22
+ OrderMailer.cancel_email(id).deliver_later
23
+ end
24
+
25
+ ::Spree::Order.prepend(self)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module Emails
3
+ module ReimbursementDecorator
4
+ def send_reimbursement_email
5
+ Spree::ReimbursementMailer.reimbursement_email(id).deliver_later
6
+ end
7
+
8
+ ::Spree::Reimbursement.prepend(self)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Emails
3
+ module ShipmentHandlerDecorator
4
+ protected
5
+
6
+ def send_shipped_email
7
+ ShipmentMailer.shipped_email(@shipment.id).deliver_later
8
+ end
9
+
10
+ ::Spree::ShipmentHandler.prepend(self)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html>
3
+ <head>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
5
+ <meta name="x-apple-disable-message-reformatting"/>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
7
+
8
+ <%= render partial: 'spree/shared/base_mailer_stylesheets' %>
9
+ </head>
10
+ <body>
11
+ <table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation">
12
+ <tr>
13
+ <td align="center">
14
+ <table class="email-content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
15
+ <%= render partial: 'spree/shared/base_mailer_header' %>
16
+ <!-- Email Body -->
17
+ <tr>
18
+ <td class="email-body" width="570" cellpadding="0" cellspacing="0">
19
+ <table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation">
20
+ <!-- Body content -->
21
+ <tbody>
22
+ <tr>
23
+ <td class="content-cell">
24
+ <div class="f-fallback">
25
+ <%= yield %>
26
+ </div>
27
+ </td>
28
+ </tr>
29
+ </tbody>
30
+ </table>
31
+ </td>
32
+ </tr>
33
+ <tr>
34
+ <td>
35
+ <%= render partial: 'spree/shared/base_mailer_footer' %>
36
+ </td>
37
+ </tr>
38
+ </table>
39
+ </td>
40
+ </tr>
41
+ <tr>
42
+ <td height="60px">&nbsp;</td>
43
+ </tr>
44
+ </table>
45
+ </body>
46
+ </html>
@@ -0,0 +1,24 @@
1
+ <h1>
2
+ <%= Spree.t('order_mailer.cancel_email.dear_customer', name: name_for(@order)) %>
3
+ </h1>
4
+ <p>
5
+ <%= Spree.t('order_mailer.cancel_email.instructions') %>
6
+ </p>
7
+
8
+ <table class="purchase" role="presentation">
9
+ <tr>
10
+ <td>
11
+ <h3> <%= Spree.t('order_mailer.cancel_email.order_summary_canceled', number: @order.number) %></h3>
12
+ </td>
13
+ </tr>
14
+ <tr>
15
+ <td colspan="2">
16
+ <%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>
17
+ </td>
18
+ </tr>
19
+ </table>
20
+ <p>
21
+ <%= Spree.t('order_mailer.cancel_email.thanks') %>
22
+ <br />
23
+ <%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
24
+ </p>
@@ -0,0 +1,12 @@
1
+ <%= Spree.t('order_mailer.cancel_email.dear_customer', name: name_for(@order)) %>
2
+
3
+ <%= Spree.t('order_mailer.cancel_email.instructions') %>
4
+
5
+ ============================================================
6
+ <%= Spree.t('order_mailer.cancel_email.order_summary_canceled', number: @order.number) %>
7
+ ============================================================
8
+ <%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>
9
+ ============================================================
10
+ <%= Spree.t('order_mailer.total') %> <%= @order.display_total %>
11
+ <%= Spree.t('order_mailer.cancel_email.thanks') %>
12
+ <%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
@@ -0,0 +1,23 @@
1
+ <h1>
2
+ <%= Spree.t('order_mailer.confirm_email.dear_customer', name: name_for(@order)) %>
3
+ </h1>
4
+ <p>
5
+ <%= Spree.t('order_mailer.confirm_email.instructions') %>
6
+ </p>
7
+ <table class="purchase" role="presentation">
8
+ <tr>
9
+ <td>
10
+ <h3><%= Spree.t('order_mailer.confirm_email.order_summary', number: @order.number) %></h3>
11
+ </td>
12
+ </tr>
13
+ <tr>
14
+ <td colspan="2">
15
+ <%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>
16
+ </td>
17
+ </tr>
18
+ </table>
19
+ <p>
20
+ <%= Spree.t('order_mailer.confirm_email.thanks') %>
21
+ <br />
22
+ <%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
23
+ </p>
@@ -0,0 +1,12 @@
1
+ <%= Spree.t('order_mailer.confirm_email.dear_customer', name: name_for(@order)) %>
2
+
3
+ <%= Spree.t('order_mailer.confirm_email.instructions') %>
4
+
5
+ ============================================================
6
+ <%= Spree.t('order_mailer.confirm_email.order_summary', number: @order.number) %>
7
+ ============================================================
8
+ <%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>
9
+ ============================================================
10
+ <%= Spree.t('order_mailer.total') %> <%= @order.display_total %>
11
+ <%= Spree.t('order_mailer.confirm_email.thanks') %>
12
+ <%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
@@ -0,0 +1,23 @@
1
+ <h1>
2
+ <%= Spree.t('order_mailer.store_owner_notification_email.heading') %>
3
+ </h1>
4
+ <p>
5
+ <%= Spree.t('order_mailer.store_owner_notification_email.instructions') %>
6
+ </p>
7
+ <table class="purchase" role="presentation">
8
+ <tr>
9
+ <td>
10
+ <h3><%= Spree.t('order_mailer.store_owner_notification_email.order_summary', number: @order.number) %></h3>
11
+ </td>
12
+ </tr>
13
+ <tr>
14
+ <td colspan="2">
15
+ <%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>
16
+ </td>
17
+ </tr>
18
+ </table>
19
+ <p>
20
+ <%= Spree.t('order_mailer.store_owner_notification_email.thanks') %>
21
+ <br />
22
+ <%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>
23
+ </p>
@@ -0,0 +1,12 @@
1
+ <%= Spree.t('order_mailer.store_owner_notification_email.heading') %>
2
+
3
+ <%= Spree.t('order_mailer.store_owner_notification_email.instructions') %>
4
+
5
+ ============================================================
6
+ <%= Spree.t('order_mailer.store_owner_notification_email.order_summary', number: @order.number) %>
7
+ ============================================================
8
+ <%= render 'spree/shared/purchased_items_table', line_items: @order.line_items, order: @order %>
9
+ ============================================================
10
+ <%= Spree.t('order_mailer.total') %> <%= @order.display_total %>
11
+ <%= Spree.t('order_mailer.store_owner_notification_email.thanks') %>
12
+ <%= Spree.t('order_mailer.store_team', store_name: current_store.name) %>