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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
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.rbindex a38f74f2e6..05efdbf34f 100644--- a/core/app/models/spree/reimbursement.rb+++ b/core/app/models/spree/reimbursement.rb@@ -5,6 +5,7 @@ module Spreeif defined?(Spree::Webhooks::HasWebhooks)include Spree::Webhooks::HasWebhooksend+ include Spree::Reimbursement::Emailsclass IncompleteReimbursementError < StandardError; end@@ -141,12 +142,6 @@ module Spreeendend- 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 anddiff --git a/core/app/models/spree/reimbursement/emails.rb b/core/app/models/spree/reimbursement/emails.rbnew file mode 100644index 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+enddiff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rbindex e22182b77a..6a272c77f5 100644--- a/core/app/models/spree/shipment.rb+++ b/core/app/models/spree/shipment.rb@@ -15,6 +15,7 @@ module Spreeif defined?(Spree::VendorConcern)include Spree::VendorConcernend+ include Spree::Shipment::Emailswith_options inverse_of: :shipments dobelongs_to :address, class_name: 'Spree::Address'diff --git a/core/app/models/spree/shipment/emails.rb b/core/app/models/spree/shipment/emails.rbnew file mode 100644index 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+enddiff --git a/core/app/models/spree/shipment_handler.rb b/core/app/models/spree/shipment_handler.rbindex ccfb4f1eb4..8486ebc5c1 100644--- a/core/app/models/spree/shipment_handler.rb+++ b/core/app/models/spree/shipment_handler.rb@@ -1,5 +1,7 @@module Spreeclass ShipmentHandler+ include Spree::Shipment::Emails+class << selfdef factory(shipment)# Do we have a specialized shipping-method-specific handler? e.g:@@ -27,12 +29,6 @@ module Spreeprotected- 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_stateorder = @shipment.orderdiff --git a/emails/app/models/spree/emails/order_decorator.rb b/emails/app/models/spree/order/emails.rbsimilarity index 91%rename from emails/app/models/spree/emails/order_decorator.rbrename to emails/app/models/spree/order/emails.rbindex 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 Emailsdef deliver_order_confirmation_emailOrderMailer.confirm_email(id).deliver_laterupdate_column(:confirmation_delivered, true)@@ -21,8 +21,6 @@ module Spreedef send_cancel_emailOrderMailer.cancel_email(id).deliver_laterend-- ::Spree::Order.prepend(self)endendenddiff --git a/emails/app/models/spree/emails/reimbursement_decorator.rb b/emails/app/models/spree/reimbursement/emails.rbsimilarity index 61%rename from emails/app/models/spree/emails/reimbursement_decorator.rbrename to emails/app/models/spree/reimbursement/emails.rbindex 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 Emailsdef send_reimbursement_emailSpree::ReimbursementMailer.reimbursement_email(id).deliver_laterend-- ::Spree::Reimbursement.prepend(self)endendenddiff --git a/emails/app/models/spree/emails/shipment_handler_decorator.rb b/emails/app/models/spree/shipment/emails.rbsimilarity index 54%rename from emails/app/models/spree/emails/shipment_handler_decorator.rbrename to emails/app/models/spree/shipment/emails.rbindex 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 Emailsdef send_shipped_emailShipmentMailer.shipped_email(@shipment.id).deliver_laterend-- ::Spree::ShipmentHandler.prepend(self)endendenddiff --git a/emails/lib/spree/emails/engine.rb b/emails/lib/spree/emails/engine.rbindex 0afe0e3cb6..3662e9e765 100644--- a/emails/lib/spree/emails/engine.rb+++ b/emails/lib/spree/emails/engine.rb@@ -5,14 +5,6 @@ module Spreeclass Engine < Rails::Engineisolate_namespace Spreeengine_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_procendendend