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.

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.rb
index 9f1660f049..70af4883d0 100644
--- a/emails/app/helpers/spree/mail_helper.rb
+++ b/emails/app/helpers/spree/mail_helper.rb
@@ -12,7 +12,7 @@ module Spree
end
def store_logo
- @order&.store&.mailer_logo || @order&.store&.logo || current_store.mailer_logo || current_store.logo
+ @store_logo ||= current_store&.mailer_logo || current_store&.logo
end
def default_logo
diff --git a/emails/app/mailers/spree/base_mailer.rb b/emails/app/mailers/spree/base_mailer.rb
index 121beaded5..3b0f8ecd59 100644
--- a/emails/app/mailers/spree/base_mailer.rb
+++ b/emails/app/mailers/spree/base_mailer.rb
@@ -3,12 +3,12 @@ module Spree
helper Spree::MailHelper
def current_store
- @current_store ||= Spree::Dependencies.current_store_finder.constantize.new.execute
+ @current_store ||= @order&.store.presence || Spree::Dependencies.current_store_finder.constantize.new.execute
end
helper_method :current_store
def from_address
- @order&.store&.mail_from_address || current_store.mail_from_address
+ current_store.mail_from_address
end
def 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.erb
index 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.rb
index 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 do
include EmailSpec::Helpers
include 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) do
order = stub_model(Spree::Order, email: '[email protected]')
@@ -159,7 +157,7 @@ describe Spree::OrderMailer, type: :mailer do
pt_br_cancel_mail = { spree: { order_mailer: { cancel_email: { order_summary_canceled: 'Resumo da Pedido [CANCELADA]' } } } }
I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail
I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail
- Spree::Store.default.update(default_locale: 'pt-BR')
+ first_store.update(default_locale: 'pt-BR')
end
after do
diff --git a/emails/spec/mailers/spree/shipment_mailer_spec.rb b/emails/spec/mailers/spree/shipment_mailer_spec.rb
index 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 do
include EmailSpec::Helpers
include 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 do
context ':from not set explicitly' do
it 'falls back to spree config' do
message = 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])
end
end
@@ -47,7 +47,7 @@ describe Spree::ShipmentMailer, type: :mailer do
I18n.enforce_available_locales = false
pt_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')
end
after do
diff --git a/emails/spec/models/spree/reimbursement_spec.rb b/emails/spec/models/spree/reimbursement_spec.rb
index 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 do
let!(: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 do
let(: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! # completed
customer_return.save!
return_item.accept!
end