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.

Skip sending a reimbursement email if send_consumer_transactional_emails is set to false (#12912)

Łukasz Adamczyk3aab58bbd28c
diff --git a/emails/app/models/spree/reimbursement/emails.rb b/emails/app/models/spree/reimbursement/emails.rb
index 1cfe575820..404b599f85 100644
--- a/emails/app/models/spree/reimbursement/emails.rb
+++ b/emails/app/models/spree/reimbursement/emails.rb
@@ -2,7 +2,7 @@ module Spree
class Reimbursement < Spree.base_class
module Emails
def send_reimbursement_email
- Spree::ReimbursementMailer.reimbursement_email(id).deliver_later
+ Spree::ReimbursementMailer.reimbursement_email(id).deliver_later if store.prefers_send_consumer_transactional_emails?
end
end
end
diff --git a/emails/spec/models/spree/reimbursement_spec.rb b/emails/spec/models/spree/reimbursement_spec.rb
index 1d4048551a..acf0e150b1 100644
--- a/emails/spec/models/spree/reimbursement_spec.rb
+++ b/emails/spec/models/spree/reimbursement_spec.rb
@@ -34,5 +34,20 @@ describe Spree::Reimbursement, type: :model do
expect(Spree::ReimbursementMailer).to receive(:reimbursement_email).with(reimbursement.id) { double(deliver_later: true) }
subject
end
+
+ context 'when send_consumer_transactional_emails store setting is set to false' do
+ before do
+ store.update!(preferred_send_consumer_transactional_emails: false)
+ end
+
+ after do
+ store.update!(preferred_send_consumer_transactional_emails: true)
+ end
+
+ it 'does not trigger the reimbursement mailer to be sent' do
+ expect(Spree::ReimbursementMailer).not_to receive(:reimbursement_email)
+ subject
+ end
+ end
end
end