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
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.rbindex 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-viewsdef 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_urlenddef set_email_localediff --git a/emails/spec/mailers/spree/order_mailer_spec.rb b/emails/spec/mailers/spree/order_mailer_spec.rbindex 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 docontext 'emails contain only urls of the store where the order was made' doit 'shows proper host url in email content' do+ ActionMailer::Base.default_url_options = { host: 'localhost' }described_class.confirm_email(order).deliver_nowexpect(ActionMailer::Base.default_url_options[:host]).to eq(order.store.url)end