Skip to content

Commit 5f24fcf

Browse files
authored
Merge pull request #5929 from magpieuk/solidus-order-index-fix
Display the store's currency in the Admin Order Index Component
2 parents 8334e9c + 50ceba8 commit 5f24fcf

File tree

8 files changed

+76
-10
lines changed

8 files changed

+76
-10
lines changed

admin/app/components/solidus_admin/orders/index/component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def total_column
153153
{
154154
header: :total,
155155
data: ->(order) do
156-
content_tag :div, number_to_currency(order.total)
156+
content_tag :div, order.display_total
157157
end
158158
}
159159
end

admin/app/components/solidus_admin/orders/show/summary/component.html.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<%= render component('ui/panel').new(title: t('.summary')) do %>
33
<%= render component('ui/details_list').new(
44
items: [
5-
{ label: t('.subtotal'), value: number_to_currency(@order.item_total), class: 'font-semibold' },
6-
{ label: t('.taxes'), value: number_to_currency(@order.additional_tax_total) },
7-
{ label: t('.shipping'), value: number_to_currency(@order.shipment_total) },
8-
{ label: link_to(t('.add_promo_code'), '#', class: "body-link"), value: number_to_currency(@order.promo_total) },
9-
{ label: link_to(t('.adjustments'), solidus_admin.order_adjustments_path(@order), class: "body-link"), value: number_to_currency(@order.adjustment_total) },
10-
{ label: t('.total'), value: number_to_currency(@order.total), class: 'font-semibold' }
5+
{ label: t('.subtotal'), value: @order.display_item_total, class: 'font-semibold' },
6+
{ label: t('.taxes'), value: @order.display_additional_tax_total },
7+
{ label: t('.shipping'), value: @order.display_shipment_total },
8+
{ label: link_to(t('.add_promo_code'), '#', class: "body-link"), value: @order.display_promo_total },
9+
{ label: link_to(t('.adjustments'), solidus_admin.order_adjustments_path(@order), class: "body-link"), value: @order.display_adjustment_total },
10+
{ label: t('.total'), value: @order.display_total, class: 'font-semibold' }
1111
]
1212
) %>
1313
<% end %>

admin/app/components/solidus_admin/users/orders/component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def total_column
106106
{
107107
header: :total,
108108
data: ->(order) do
109-
content_tag :div, number_to_currency(order.total)
109+
content_tag :div, order.display_total
110110
end
111111
}
112112
end

admin/spec/features/orders/index_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@
1717
expect(page).to be_axe_clean
1818
end
1919

20+
context 'with different currency' do
21+
around do |example|
22+
currency_was = Spree::Config.currency
23+
Spree::Config.currency = 'EUR'
24+
example.run
25+
Spree::Config.currency = currency_was
26+
end
27+
28+
it 'displays correct currency' do
29+
create(:order, total: 19.99)
30+
visit "/admin/orders"
31+
click_on "In Progress"
32+
33+
expect(page).to have_content("€19.99")
34+
end
35+
end
36+
2037
context "with multiple stores", :js do
2138
let!(:order_in_default_store) { create :order }
2239
let(:another_store) { create :store, name: "Another Store" }

admin/spec/features/orders/show_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,33 @@
137137
end
138138
end
139139

140+
describe 'summary panel' do
141+
shared_examples_for 'summary panel' do
142+
let!(:order) { create(:order, number: "R123456789", total: 4.99, currency:) }
143+
let(:currency) { 'USD' }
144+
145+
it 'displays order summary correctly' do
146+
visit "/admin/orders/R123456789"
147+
148+
expect(page).to have_content("Summary")
149+
expect(page).to have_content(/Subtotal\s#{Regexp.escape(order.display_item_total.to_s)}/)
150+
expect(page).to have_content(/Taxes\s#{Regexp.escape(order.display_additional_tax_total.to_s)}/)
151+
expect(page).to have_content(/Shipping\s#{Regexp.escape(order.display_shipment_total.to_s)}/)
152+
expect(page).to have_content(/Add Promo Code\s#{Regexp.escape(order.display_promo_total.to_s)}/)
153+
expect(page).to have_content(/Adjustments\s#{Regexp.escape(order.display_adjustment_total.to_s)}/)
154+
expect(page).to have_content(/Total\s#{Regexp.escape(order.display_total.to_s)}/)
155+
end
156+
end
157+
158+
include_examples "summary panel"
159+
160+
context 'with different currency' do
161+
include_examples "summary panel" do
162+
let(:currency) { 'EUR' }
163+
end
164+
end
165+
end
166+
140167
private
141168

142169
def open_customer_menu

admin/spec/features/users_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@
184184
end
185185

186186
context "when a user has ordered before" do
187+
let!(:user) { create(:user, :with_orders, email: "[email protected]") }
188+
187189
before do
188-
create(:user, :with_orders, email: "[email protected]")
189190
visit "/admin/users"
190191
find_row("[email protected]").click
191192
click_on "Order History"
@@ -204,6 +205,19 @@
204205
expect(page).to have_content("Payment")
205206
expect(page).not_to have_content("No Orders found.")
206207
end
208+
209+
context 'with a different currency' do
210+
around do |example|
211+
currency_was = Spree::Config.currency
212+
Spree::Config.currency = 'EUR'
213+
example.run
214+
Spree::Config.currency = currency_was
215+
end
216+
217+
it 'displays correct currency' do
218+
page.assert_selector('section table td:last-child', exact_text: /€\d\.\d{2}/, count: user.orders.count)
219+
end
220+
end
207221
end
208222
end
209223

core/app/models/spree/order.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class CannotRebuildShipments < StandardError; end
5252
:total_available_store_credit,
5353
:item_total_before_tax,
5454
:shipment_total_before_tax,
55-
:item_total_excluding_vat
55+
:item_total_excluding_vat,
56+
:promo_total
5657
)
5758
alias :display_ship_total :display_shipment_total
5859

core/spec/models/spree/order_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@
358358
end
359359
end
360360

361+
describe "#promo_total" do
362+
it "returns the value as a spree money" do
363+
order.promo_total = 10.55
364+
expect(order.display_promo_total).to eq(Spree::Money.new(10.55))
365+
end
366+
end
367+
361368
context "#currency" do
362369
context "when object currency is ABC" do
363370
before { order.currency = "ABC" }

0 commit comments

Comments
 (0)