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
Skip sending a shipment email if send_consumer_transactional_emails is set to false (#12918)
Łukasz Adamczykcceb2a49099e
diff --git a/emails/app/models/spree/shipment/emails.rb b/emails/app/models/spree/shipment/emails.rbindex 80db0a3b3a..7506b069e3 100644--- a/emails/app/models/spree/shipment/emails.rb+++ b/emails/app/models/spree/shipment/emails.rb@@ -2,7 +2,7 @@ module Spreeclass Shipment < Spree.base_classmodule Emailsdef send_shipped_email- ShipmentMailer.shipped_email(@shipment.id).deliver_later+ ShipmentMailer.shipped_email(@shipment.id).deliver_later if @shipment.store.prefers_send_consumer_transactional_emails?endendenddiff --git a/emails/spec/models/spree/reimbursement_spec.rb b/emails/spec/models/spree/reimbursement_spec.rbindex acf0e150b1..f14ce041c1 100644--- a/emails/spec/models/spree/reimbursement_spec.rb+++ b/emails/spec/models/spree/reimbursement_spec.rb@@ -37,11 +37,7 @@ describe Spree::Reimbursement, type: :model docontext 'when send_consumer_transactional_emails store setting is set to false' dobefore do- store.update!(preferred_send_consumer_transactional_emails: false)- end-- after do- store.update!(preferred_send_consumer_transactional_emails: true)+ allow_any_instance_of(Spree::Store).to receive(:prefers_send_consumer_transactional_emails?).and_return(false)endit 'does not trigger the reimbursement mailer to be sent' dodiff --git a/emails/spec/models/spree/shipment_spec.rb b/emails/spec/models/spree/shipment_spec.rbindex 150f693f9c..d7c8b2bec2 100644--- a/emails/spec/models/spree/shipment_spec.rb+++ b/emails/spec/models/spree/shipment_spec.rb@@ -35,6 +35,17 @@ describe Spree::Shipment, type: :model doshipment.ship!expect(shipment_id).to eq(shipment.id)end++ context 'when send_consumer_transactional_emails store setting is set to false' do+ before do+ allow(shipment.store).to receive(:prefers_send_consumer_transactional_emails?).and_return(false)+ end++ it 'does not trigger the shipment mailer to be sent' do+ expect(Spree::ShipmentMailer).not_to receive(:shipped_email)+ shipment.ship!+ end+ endendendend