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: order confirmation email totals add up when shipping is discounted (#14725)
Damian Legawiecb3c1e0511a27
diff --git a/spree/emails/app/views/spree/shared/_purchased_items_table.html.erb b/spree/emails/app/views/spree/shared/_purchased_items_table.html.erbindex 07cd196cea..4e0d8be9cb 100644--- a/spree/emails/app/views/spree/shared/_purchased_items_table.html.erb+++ b/spree/emails/app/views/spree/shared/_purchased_items_table.html.erb@@ -13,7 +13,7 @@<%= render 'spree/shared/purchased_items_table/summary_row',label: Spree.t(:shipping),sub: name,- value: Spree::Money.new(shipments.sum(&:discounted_cost), currency: order.currency) %>+ value: Spree::Money.new(shipments.sum(&:cost), currency: order.currency) %><% end %><% if order.additional_tax_total != 0 %><%= render 'spree/shared/purchased_items_table/summary_row',diff --git a/spree/emails/app/views/spree/shared/_purchased_items_table.text.erb b/spree/emails/app/views/spree/shared/_purchased_items_table.text.erbindex 47d672f4b7..bea3dd9185 100644--- a/spree/emails/app/views/spree/shared/_purchased_items_table.text.erb+++ b/spree/emails/app/views/spree/shared/_purchased_items_table.text.erb@@ -8,7 +8,7 @@<% end %><% order.fulfillments.group_by { |f| f.selected_delivery_rate.try(:name) }.each do |name, shipments| %>- <%= Spree.t(:shipping) %>: <%= name %> <%= Spree::Money.new(shipments.sum(&:discounted_cost), currency: order.currency) %>+ <%= Spree.t(:shipping) %>: <%= name %> <%= Spree::Money.new(shipments.sum(&:cost), currency: order.currency) %><% end %><% if order.additional_tax_total != 0 %>diff --git a/spree/emails/spec/mailers/spree/order_mailer_spec.rb b/spree/emails/spec/mailers/spree/order_mailer_spec.rbindex 3e2a3d9cc8..8494a89e9a 100644--- a/spree/emails/spec/mailers/spree/order_mailer_spec.rb+++ b/spree/emails/spec/mailers/spree/order_mailer_spec.rb@@ -170,6 +170,22 @@ describe Spree::OrderMailer, type: :mailer doendend+ context 'when a promotion makes shipping free' do+ before do+ fulfillment = order.fulfillments.first+ fulfillment.update_columns(cost: 5, discount_total: -5)+ order.discounts.create!(fulfillment: fulfillment, amount: -5, kind: 'promotion', label: 'Free Shipping')+ end++ it 'shows the shipping cost before the discount, so the lines add up to the total' do+ body = described_class.confirm_email(order).text_part.body.to_s++ expect(body).to match(/Free Shipping -\$5\.00/)+ expect(body).to match(/#{Spree.t(:shipping)}: .*\$5\.00/)+ expect(body).not_to match(/#{Spree.t(:shipping)}: .*\$0\.00/)+ end+ end+context 'displays unit costs from line item' do# Regression test for #2772