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
Fix: turning off customer emails no longer stops the store's new order email (#14724)
Damian Legawiec238f740c82af
diff --git a/spree/emails/app/subscribers/spree/order_email_subscriber.rb b/spree/emails/app/subscribers/spree/order_email_subscriber.rbindex bb839e5898..499c58b006 100644--- a/spree/emails/app/subscribers/spree/order_email_subscriber.rb+++ b/spree/emails/app/subscribers/spree/order_email_subscriber.rb@@ -13,16 +13,18 @@ module Spreedef send_confirmation_email(event)order = find_order(event)return unless order++ send_customer_confirmation(order, event)+ send_store_owner_notification(order)+ end++ def send_customer_confirmation(order, event)return if order.confirmation_delivered?return if event.payload['notify_customer'] == false-- store = order.store- return unless store.prefers_send_consumer_transactional_emails?+ return unless order.store.prefers_send_consumer_transactional_emails?OrderMailer.confirm_email(order.id).deliver_laterorder.update_column(:confirmation_delivered, true)-- send_store_owner_notification(order) if should_notify_store_owner?(order)enddef resend_confirmation_email(event)@@ -55,11 +57,6 @@ module Spreeorder.update_column(:store_owner_notification_delivered, true)end- def should_notify_store_owner?(order)- order.store.new_order_notifications_email.present? &&- !order.store_owner_notification_delivered?- end-def find_order(event)order_id = event.payload['id']Spree::Order.find_by_prefix_id(order_id)diff --git a/spree/emails/spec/subscribers/spree/order_email_subscriber_spec.rb b/spree/emails/spec/subscribers/spree/order_email_subscriber_spec.rbindex 66ceb04852..1736643326 100644--- a/spree/emails/spec/subscribers/spree/order_email_subscriber_spec.rb+++ b/spree/emails/spec/subscribers/spree/order_email_subscriber_spec.rb@@ -62,6 +62,13 @@ RSpec.describe Spree::OrderEmailSubscriber doit 'does not send confirmation email' doexpect(Spree::OrderMailer).not_to receive(:confirm_email)+ allow(Spree::OrderMailer).to receive(:store_owner_notification_email).and_return(double(deliver_later: true))++ subscriber.send(:send_confirmation_email, mock_event(order))+ end++ it 'still sends store owner notification email' do+ expect(Spree::OrderMailer).to receive(:store_owner_notification_email).with(order.id).and_return(double(deliver_later: true))subscriber.send(:send_confirmation_email, mock_event(order))end@@ -87,12 +94,20 @@ RSpec.describe Spree::OrderEmailSubscriber doendcontext 'when notify_customer is false in payload' do+ before { allow(Spree::OrderMailer).to receive(:store_owner_notification_email).and_return(double(deliver_later: true)) }+it 'does not send confirmation email' doexpect(Spree::OrderMailer).not_to receive(:confirm_email)subscriber.send(:send_confirmation_email, mock_event(order, notify_customer: false))end+ it 'still sends store owner notification email' do+ expect(Spree::OrderMailer).to receive(:store_owner_notification_email).with(order.id)++ subscriber.send(:send_confirmation_email, mock_event(order, notify_customer: false))+ end+it 'does not mark confirmation as delivered' doexpect {subscriber.send(:send_confirmation_email, mock_event(order, notify_customer: false))