Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Replace decorator usage in `spree_emails` with plain ruby modules (#12069)

Damian Legawiecdfcbb35a4f85
diff --git a/core/app/models/spree/reimbursement.rb b/core/app/models/spree/reimbursement.rb
index a38f74f2e6..05efdbf34f 100644
--- a/core/app/models/spree/reimbursement.rb
+++ b/core/app/models/spree/reimbursement.rb
@@ -5,6 +5,7 @@ module Spree
if defined?(Spree::Webhooks::HasWebhooks)
include Spree::Webhooks::HasWebhooks
end
+ include Spree::Reimbursement::Emails
class IncompleteReimbursementError < StandardError; end
@@ -141,12 +142,6 @@ module Spree
end
end
- def send_reimbursement_email
- # you can overwrite this method in your application / extension to send out the confirmation email
- # or use `spree_emails` gem
- # YourEmailVendor.deliver_reimbursement_email(id) # `id` = ID of the Reimbursement being sent, you can also pass the entire object using `self`
- end
-
# If there are multiple different reimbursement types for a single
# reimbursement we open ourselves to a one-cent rounding error for every
# type over the first one. This is due to how we round #unpaid_amount and
diff --git a/core/app/models/spree/reimbursement/emails.rb b/core/app/models/spree/reimbursement/emails.rb
new file mode 100644
index 0000000000..7cf4a6ae39
--- /dev/null
+++ b/core/app/models/spree/reimbursement/emails.rb
@@ -0,0 +1,11 @@
+module Spree
+ class Reimbursement < Spree::Base
+ module Emails
+ def send_reimbursement_email
+ # you can overwrite this method in your application / extension to send out the confirmation email
+ # or use `spree_emails` gem
+ # YourEmailVendor.deliver_reimbursement_email(id) # `id` = ID of the Reimbursement being sent, you can also pass the entire object using `self`
+ end
+ end
+ end
+end
diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb
index e22182b77a..6a272c77f5 100644
--- a/core/app/models/spree/shipment.rb
+++ b/core/app/models/spree/shipment.rb
@@ -15,6 +15,7 @@ module Spree
if defined?(Spree::VendorConcern)
include Spree::VendorConcern
end
+ include Spree::Shipment::Emails
with_options inverse_of: :shipments do
belongs_to :address, class_name: 'Spree::Address'
diff --git a/core/app/models/spree/shipment/emails.rb b/core/app/models/spree/shipment/emails.rb
new file mode 100644
index 0000000000..75882859f4
--- /dev/null
+++ b/core/app/models/spree/shipment/emails.rb
@@ -0,0 +1,11 @@
+module Spree
+ class Shipment < Spree::Base
+ module Emails
+ def send_shipped_email
+ # you can overwrite this method in your application / extension to send out the confirmation email
+ # or use `spree_emails` gem
+ # YourEmailVendor.deliver_shipment_notification_email(@shipment.id)
+ end
+ end
+ end
+end
diff --git a/core/app/models/spree/shipment_handler.rb b/core/app/models/spree/shipment_handler.rb
index ccfb4f1eb4..8486ebc5c1 100644
--- a/core/app/models/spree/shipment_handler.rb
+++ b/core/app/models/spree/shipment_handler.rb
@@ -1,5 +1,7 @@
module Spree
class ShipmentHandler
+ include Spree::Shipment::Emails
+
class << self
def factory(shipment)
# Do we have a specialized shipping-method-specific handler? e.g:
@@ -27,12 +29,6 @@ module Spree
protected
- def send_shipped_email
- # you can overwrite this method in your application / extension to send out the confirmation email
- # or use `spree_emails` gem
- # YourEmailVendor.deliver_shipment_notification_email(@shipment.id)
- end
-
def update_order_shipment_state
order = @shipment.order
diff --git a/emails/app/models/spree/emails/order_decorator.rb b/emails/app/models/spree/order/emails.rb
similarity index 91%
rename from emails/app/models/spree/emails/order_decorator.rb
rename to emails/app/models/spree/order/emails.rb
index 8274761f60..ca5e1637b3 100644
--- a/emails/app/models/spree/emails/order_decorator.rb
+++ b/emails/app/models/spree/order/emails.rb
@@ -1,6 +1,6 @@
module Spree
- module Emails
- module OrderDecorator
+ class Order < Spree::Base
+ module Emails
def deliver_order_confirmation_email
OrderMailer.confirm_email(id).deliver_later
update_column(:confirmation_delivered, true)
@@ -21,8 +21,6 @@ module Spree
def send_cancel_email
OrderMailer.cancel_email(id).deliver_later
end
-
- ::Spree::Order.prepend(self)
end
end
end
diff --git a/emails/app/models/spree/emails/reimbursement_decorator.rb b/emails/app/models/spree/reimbursement/emails.rb
similarity index 61%
rename from emails/app/models/spree/emails/reimbursement_decorator.rb
rename to emails/app/models/spree/reimbursement/emails.rb
index e96d525ab1..76f654a777 100644
--- a/emails/app/models/spree/emails/reimbursement_decorator.rb
+++ b/emails/app/models/spree/reimbursement/emails.rb
@@ -1,11 +1,9 @@
module Spree
- module Emails
- module ReimbursementDecorator
+ class Reimbursement < Spree::Base
+ module Emails
def send_reimbursement_email
Spree::ReimbursementMailer.reimbursement_email(id).deliver_later
end
-
- ::Spree::Reimbursement.prepend(self)
end
end
end
diff --git a/emails/app/models/spree/emails/shipment_handler_decorator.rb b/emails/app/models/spree/shipment/emails.rb
similarity index 54%
rename from emails/app/models/spree/emails/shipment_handler_decorator.rb
rename to emails/app/models/spree/shipment/emails.rb
index 5cccf02266..987129bf52 100644
--- a/emails/app/models/spree/emails/shipment_handler_decorator.rb
+++ b/emails/app/models/spree/shipment/emails.rb
@@ -1,13 +1,9 @@
module Spree
- module Emails
- module ShipmentHandlerDecorator
- protected
-
+ class Shipment < Spree::Base
+ module Emails
def send_shipped_email
ShipmentMailer.shipped_email(@shipment.id).deliver_later
end
-
- ::Spree::ShipmentHandler.prepend(self)
end
end
end
diff --git a/emails/lib/spree/emails/engine.rb b/emails/lib/spree/emails/engine.rb
index 0afe0e3cb6..3662e9e765 100644
--- a/emails/lib/spree/emails/engine.rb
+++ b/emails/lib/spree/emails/engine.rb
@@ -5,14 +5,6 @@ module Spree
class Engine < Rails::Engine
isolate_namespace Spree
engine_name 'spree_emails'
-
- def self.activate
- Dir.glob(File.join(File.dirname(__FILE__), '../../../app/**/*_decorator*.rb')).sort.each do |c|
- Rails.configuration.cache_classes ? require(c) : load(c)
- end
- end
-
- config.to_prepare &method(:activate).to_proc
end
end
end