Skip to content

Commit c7d6123

Browse files
committed
Implement order/show/summary component using ui/details_list
In this commit, we've added the `order/show/summary` component, leveraging the recently introduced `ui/details_list`. The component is specifically tailored to display order-related information such as subtotal, taxes, shipping costs, promo code deductions, adjustments, and the total amount.
1 parent f416661 commit c7d6123

7 files changed

Lines changed: 85 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<%= page_with_sidebar do %>
1212
<%= page_with_sidebar_main do %>
1313
<%= render component("orders/cart").new(order: @order) %>
14+
<%= render component("orders/show/summary").new(order: @order) %>
1415
<% end %>
1516

1617
<%= page_with_sidebar_aside do %>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="<%= stimulus_id %> w-full">
2+
<%= render component('ui/panel').new(title: t('.summary')) do %>
3+
<%= render component('ui/details_list').new(
4+
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'), '#', class: "body-link"), value: number_to_currency(@order.adjustment_total) },
10+
{ label: t('.total'), value: number_to_currency(@order.total), class: 'font-semibold' }
11+
]
12+
) %>
13+
<% end %>
14+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class SolidusAdmin::Orders::Show::Summary::Component < SolidusAdmin::BaseComponent
4+
def initialize(order:)
5+
@order = order
6+
end
7+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
en:
2+
summary: Summary
3+
subtotal: Subtotal
4+
taxes: Taxes
5+
shipping: Shipping
6+
add_promo_code: Add Promo Code
7+
adjustments: Adjustments
8+
total: Total
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
# @component "orders/show/summary"
4+
class SolidusAdmin::Orders::Show::Summary::ComponentPreview < ViewComponent::Preview
5+
include SolidusAdmin::Preview
6+
7+
def overview
8+
order = fake_order(item_total: 340, additional_tax_total: 10, shipment_total: 20, promo_total: 10, adjustment_total: 20)
9+
render_with_template(locals: { order: order })
10+
end
11+
12+
# @param item_total [Float]
13+
# @param additional_tax_total [Float]
14+
# @param shipment_total [Float]
15+
# @param promo_total [Float]
16+
# @param adjustment_total [Float]
17+
def playground(item_total: 100, additional_tax_total: 10, shipment_total: 5, promo_total: 0, adjustment_total: 0)
18+
fake_order = fake_order(
19+
item_total: item_total,
20+
additional_tax_total: additional_tax_total,
21+
shipment_total: shipment_total,
22+
promo_total: promo_total,
23+
adjustment_total: adjustment_total
24+
)
25+
26+
render current_component.new(order: fake_order)
27+
end
28+
29+
private
30+
31+
def fake_order(item_total:, additional_tax_total:, shipment_total:, promo_total:, adjustment_total:)
32+
order = Spree::Order.new
33+
34+
order.define_singleton_method(:item_total) { item_total }
35+
order.define_singleton_method(:additional_tax_total) { additional_tax_total }
36+
order.define_singleton_method(:shipment_total) { shipment_total }
37+
order.define_singleton_method(:promo_total) { promo_total }
38+
order.define_singleton_method(:adjustment_total) { adjustment_total }
39+
order.define_singleton_method(:total) {
40+
item_total.to_f + additional_tax_total.to_f + shipment_total.to_f - promo_total.to_f - adjustment_total.to_f
41+
}
42+
43+
order
44+
end
45+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= render current_component.new(order: order) %>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
RSpec.describe SolidusAdmin::Orders::Show::Summary::Component, type: :component do
6+
it "renders the overview preview" do
7+
render_preview(:overview)
8+
end
9+
end

0 commit comments

Comments
 (0)