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.

Override emails host so it always matches the store which sent the email (#12949)

Damian Legawieca43174089b0d
diff --git a/core/app/mailers/spree/base_mailer.rb b/core/app/mailers/spree/base_mailer.rb
index 0a4c3d2913..2c2301b70b 100644
--- a/core/app/mailers/spree/base_mailer.rb
+++ b/core/app/mailers/spree/base_mailer.rb
@@ -39,8 +39,12 @@ module Spree
# this is only a fail-safe solution if developer didn't set this in environment files
# http://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-in-action-mailer-views
def ensure_default_action_mailer_url_host(store_url = nil)
+ host_url = store_url.presence || current_store.try(:url_or_custom_domain)
+
+ return if host_url.blank?
+
ActionMailer::Base.default_url_options ||= {}
- ActionMailer::Base.default_url_options[:host] ||= store_url.presence || current_store.url_or_custom_domain
+ ActionMailer::Base.default_url_options[:host] = host_url
end
def set_email_locale
diff --git a/emails/spec/mailers/spree/order_mailer_spec.rb b/emails/spec/mailers/spree/order_mailer_spec.rb
index 16578986f8..c911fd119a 100644
--- a/emails/spec/mailers/spree/order_mailer_spec.rb
+++ b/emails/spec/mailers/spree/order_mailer_spec.rb
@@ -261,6 +261,7 @@ describe Spree::OrderMailer, type: :mailer do
context 'emails contain only urls of the store where the order was made' do
it 'shows proper host url in email content' do
+ ActionMailer::Base.default_url_options = { host: 'localhost' }
described_class.confirm_email(order).deliver_now
expect(ActionMailer::Base.default_url_options[:host]).to eq(order.store.url)
end