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 store branding in invitation and newsletter emails
Damian Legawiec8413e6756e59
diff --git a/spree/core/app/mailers/spree/invitation_mailer.rb b/spree/core/app/mailers/spree/invitation_mailer.rbindex 35862f944a..50e5ff6dff 100644--- a/spree/core/app/mailers/spree/invitation_mailer.rb+++ b/spree/core/app/mailers/spree/invitation_mailer.rb@@ -3,6 +3,10 @@ module Spree# invitation email, sending email to the invited to let them know they have been invited to join a store/account/vendordef invitation_email(invitation)@invitation = invitation+ # The shared header/footer and from/reply-to addresses read+ # current_store — without this, background delivery falls back to the+ # default store's branding on multi-store installs.+ @current_store = invitation.storewith_store_locale(invitation.store) domail(to: invitation.email,from: from_address,@@ -15,6 +19,7 @@ module Spree# sending email to the inviter to let them know the invitee has accepted the invitationdef invitation_accepted(invitation)@invitation = invitation+ @current_store = invitation.storewith_store_locale(invitation.store) domail(to: invitation.inviter.email,from: from_address,diff --git a/spree/core/spec/mailers/spree/invitation_mailer_spec.rb b/spree/core/spec/mailers/spree/invitation_mailer_spec.rbindex 3c4acb2d81..de0846f0cb 100644--- a/spree/core/spec/mailers/spree/invitation_mailer_spec.rb+++ b/spree/core/spec/mailers/spree/invitation_mailer_spec.rb@@ -11,6 +11,24 @@ RSpec.describe Spree::InvitationMailer, type: :mailer dodescribe '#invitation_email' dosubject(:mail) { described_class.invitation_email(invitation) }+ context 'for an invitation on a non-default store' do+ let(:other_store) do+ create(:store, name: 'Second Store', mail_from_address: '[email protected]',+ url: 'second.example.com')+ end+ let(:invitation) do+ create(:invitation, email: '[email protected]', inviter: inviter, resource: other_store, skip_email: true)+ end++ # Regression: the shared header/footer and from address read+ # current_store, which used to fall back to the default store when+ # delivering from a background job.+ it 'brands the email with the invitation store, not the default store' do+ expect(mail.from).to eq(['[email protected]'])+ expect(mail.body.encoded).to include('Second Store')+ end+ end+it 'renders the subject' doexpect(mail.subject).to eq(Spree.t('invitation_mailer.invitation_email.subject', resource_name: store.name)diff --git a/spree/emails/app/mailers/spree/newsletter_mailer.rb b/spree/emails/app/mailers/spree/newsletter_mailer.rbindex ccbe87e1f0..4e6927b029 100644--- a/spree/emails/app/mailers/spree/newsletter_mailer.rb+++ b/spree/emails/app/mailers/spree/newsletter_mailer.rb@@ -3,6 +3,9 @@ module Spreedef email_confirmation(subscriber, redirect_url: nil)@subscriber = subscriberstore = subscriber.store || Spree::Current.store || Spree::Store.default+ # The shared header/footer and from address read current_store — set it+ # to the subscriber's store so multi-store installs brand correctly.+ @current_store = storebase_url = redirect_url.presence || store.storefront_url@confirm_email_url = append_token(base_url, @subscriber.verification_token)with_store_locale(store) dodiff --git a/spree/emails/spec/mailers/spree/newsletter_mailer_spec.rb b/spree/emails/spec/mailers/spree/newsletter_mailer_spec.rbindex e6fcdf1a88..b40ed3205f 100644--- a/spree/emails/spec/mailers/spree/newsletter_mailer_spec.rb+++ b/spree/emails/spec/mailers/spree/newsletter_mailer_spec.rb@@ -5,6 +5,24 @@ describe Spree::NewsletterMailer, type: :mailer dolet(:subscriber) { create(:newsletter_subscriber, :unverified, email: '[email protected]', store: store) }describe '#email_confirmation' do+ context 'for a subscriber of a non-default store' do+ let(:other_store) do+ create(:store, name: 'Second Store', mail_from_address: '[email protected]',+ url: 'second.example.com')+ end+ let(:subscriber) { create(:newsletter_subscriber, :unverified, email: '[email protected]', store: other_store) }++ # Regression: the shared header/footer and from address read+ # current_store, which used to fall back to the default store when+ # delivering from a background job.+ it 'brands the email with the subscriber store, not the default store' do+ message = described_class.email_confirmation(subscriber)++ expect(message.from).to eq(['[email protected]'])+ expect(message.body.encoded).to include('Second Store')+ end+ end+context 'when a redirect_url is provided' doit 'builds the confirmation link from the redirect URL with the verification token appended' domessage = described_class.email_confirmation(subscriber, redirect_url: 'https://storefront.example.com/newsletter/confirm')