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
Simplify current store handling in emails
Damian Legawiec3e85eef5cfde
diff --git a/emails/app/helpers/spree/mail_helper.rb b/emails/app/helpers/spree/mail_helper.rbindex 9f1660f049..70af4883d0 100644--- a/emails/app/helpers/spree/mail_helper.rb+++ b/emails/app/helpers/spree/mail_helper.rb@@ -12,7 +12,7 @@ module Spreeenddef store_logo- @order&.store&.mailer_logo || @order&.store&.logo || current_store.mailer_logo || current_store.logo+ @store_logo ||= current_store&.mailer_logo || current_store&.logoenddef default_logodiff --git a/emails/app/mailers/spree/base_mailer.rb b/emails/app/mailers/spree/base_mailer.rbindex 121beaded5..3b0f8ecd59 100644--- a/emails/app/mailers/spree/base_mailer.rb+++ b/emails/app/mailers/spree/base_mailer.rb@@ -3,12 +3,12 @@ module Spreehelper Spree::MailHelperdef current_store- @current_store ||= Spree::Dependencies.current_store_finder.constantize.new.execute+ @current_store ||= @order&.store.presence || Spree::Dependencies.current_store_finder.constantize.new.executeendhelper_method :current_storedef from_address- @order&.store&.mail_from_address || current_store.mail_from_address+ current_store.mail_from_addressenddef money(amount, currency = nil)diff --git a/emails/app/views/spree/shared/_base_mailer_header.html.erb b/emails/app/views/spree/shared/_base_mailer_header.html.erbindex 695b21b69e..51ac35daf8 100644--- a/emails/app/views/spree/shared/_base_mailer_header.html.erb+++ b/emails/app/views/spree/shared/_base_mailer_header.html.erb@@ -1,13 +1,8 @@<!-- You can override this template to design your own header. -->-<% store_name = @order&.store&.name || current_store.name %><tr><td class="email-masthead">- <% if frontend_available? %>- <%= link_to spree.root_url, class: 'template-label' do %>- <%= image_tag logo_path, class: 'logo', alt: store_name, title: store_name %>- <% end %>- <% else %>- <%= image_tag logo_path, class: 'logo', alt: store_name, title: store_name %>+ <%= link_to current_store.url, class: 'template-label' do %>+ <%= image_tag logo_path, class: 'logo', alt: current_store.name, title: current_store.name %><% end %></td></tr>diff --git a/emails/spec/mailers/spree/order_mailer_spec.rb b/emails/spec/mailers/spree/order_mailer_spec.rbindex 5af3feaf23..56332d72ba 100644--- a/emails/spec/mailers/spree/order_mailer_spec.rb+++ b/emails/spec/mailers/spree/order_mailer_spec.rb@@ -5,10 +5,8 @@ describe Spree::OrderMailer, type: :mailer doinclude EmailSpec::Helpersinclude EmailSpec::Matchers- before { create(:store, default_locale: nil) }-- let(:first_store) { create(:store, name: 'First Store', default_locale: nil) }- let(:second_store) { create(:store, name: 'Second Store', url: 'other.example.com', default_locale: nil) }+ let(:first_store) { create(:store, name: 'First Store') }+ let(:second_store) { create(:store, name: 'Second Store', url: 'other.example.com') }let(:order) doorder = stub_model(Spree::Order, email: '[email protected]')@@ -159,7 +157,7 @@ describe Spree::OrderMailer, type: :mailer dopt_br_cancel_mail = { spree: { order_mailer: { cancel_email: { order_summary_canceled: 'Resumo da Pedido [CANCELADA]' } } } }I18n.backend.store_translations :'pt-BR', pt_br_confirm_mailI18n.backend.store_translations :'pt-BR', pt_br_cancel_mail- Spree::Store.default.update(default_locale: 'pt-BR')+ first_store.update(default_locale: 'pt-BR')endafter dodiff --git a/emails/spec/mailers/spree/shipment_mailer_spec.rb b/emails/spec/mailers/spree/shipment_mailer_spec.rbindex ac573b7763..d388b59825 100644--- a/emails/spec/mailers/spree/shipment_mailer_spec.rb+++ b/emails/spec/mailers/spree/shipment_mailer_spec.rb@@ -5,7 +5,7 @@ describe Spree::ShipmentMailer, type: :mailer doinclude EmailSpec::Helpersinclude EmailSpec::Matchers- let!(:store) { create(:store, default_locale: nil) }+ let!(:store) { create(:store) }let(:order) { stub_model(Spree::Order, number: 'R12345', store: store, email: '[email protected]') }let(:shipping_method) { stub_model(Spree::ShippingMethod, name: 'USPS') }@@ -23,7 +23,7 @@ describe Spree::ShipmentMailer, type: :mailer docontext ':from not set explicitly' doit 'falls back to spree config' domessage = Spree::ShipmentMailer.shipped_email(shipment)- expect(message.from).to eq([Spree::Store.default.mail_from_address])+ expect(message.from).to eq([store.mail_from_address])endend@@ -47,7 +47,7 @@ describe Spree::ShipmentMailer, type: :mailer doI18n.enforce_available_locales = falsept_br_shipped_email = { spree: { shipment_mailer: { shipped_email: { dear_customer: 'Caro Cliente,' } } } }I18n.backend.store_translations :'pt-BR', pt_br_shipped_email- Spree::Store.default.update(default_locale: 'pt-BR')+ store.update(default_locale: 'pt-BR')endafter dodiff --git a/emails/spec/models/spree/reimbursement_spec.rb b/emails/spec/models/spree/reimbursement_spec.rbindex 0ff07ca222..2474058a23 100644--- a/emails/spec/models/spree/reimbursement_spec.rb+++ b/emails/spec/models/spree/reimbursement_spec.rb@@ -9,11 +9,12 @@ describe Spree::Reimbursement, type: :model dolet!(:tax_rate) { nil }let!(:tax_zone) { create(:zone_with_country, default_tax: true) }- let(:order) { create(:order_with_line_items, state: 'payment', line_items_count: 1, line_items_price: line_items_price, shipment_cost: 0) }+ let(:store) { create(:store) }+ let(:order) { create(:shipped_order, line_items_count: 1, line_items_price: line_items_price, shipment_cost: 0, store: store) }let(:line_items_price) { BigDecimal(10) }let(:line_item) { order.line_items.first }let(:inventory_unit) { line_item.inventory_units.first }- let(:payment) { build(:payment, amount: payment_amount, order: order, state: 'completed') }+ let(:payment) { order.payments.first }let(:payment_amount) { order.total }let(:customer_return) { build(:customer_return, return_items: [return_item]) }let(:return_item) { build(:return_item, inventory_unit: inventory_unit) }@@ -25,17 +26,6 @@ describe Spree::Reimbursement, type: :model dolet(:store_credit_reimbursement_type) { create(:reimbursement_type, name: 'StoreCredit', type: 'Spree::ReimbursementType::StoreCredit') }before do- order.shipments.each do |shipment|- shipment.inventory_units.update_all state: 'shipped'- shipment.update_column('state', 'shipped')- end- order.reload- order.update_with_updater!- if payment- payment.save!- order.next! # confirm- end- order.next! # completedcustomer_return.save!return_item.accept!end