Skip to content

Commit 9413383

Browse files
authored
Merge pull request #5512 from nebulab/rainerd/admin/order-summary
[Admin] Add `order/show/summary` component
2 parents 56d2024 + c7d6123 commit 9413383

15 files changed

Lines changed: 159 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div class="<%= stimulus_id %>">
2+
<ul class="text-sm">
3+
<% @items.each do |item| %>
4+
<li class="flex justify-between py-2 <%= item[:class] %>">
5+
<span><%= item[:label] %></span>
6+
<span><%= item[:value] %></span>
7+
</li>
8+
<% end %>
9+
</ul>
10+
</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::UI::DetailsList::Component < SolidusAdmin::BaseComponent
4+
def initialize(items:)
5+
@items = items
6+
end
7+
end
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
# @component "ui/details_list"
4+
class SolidusAdmin::UI::DetailsList::ComponentPreview < ViewComponent::Preview
5+
include SolidusAdmin::Preview
6+
7+
def overview
8+
render_with_template
9+
end
10+
11+
# @param items select { choices: [[Order details, './data/example1.json'], [Product details, './data/example2.json'], [Account details, './data/example3.json']] }
12+
def playground(items: './data/example1.json')
13+
parsed_items = JSON.parse(
14+
File.read(File.join(__dir__, items)),
15+
symbolize_names: true
16+
)
17+
18+
render current_component.new(items: parsed_items)
19+
end
20+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%= render current_component.new(
2+
items: [
3+
{ label: 'Subtotal', value: '€90.00', class: 'font-semibold' },
4+
{ label: 'Taxes', value: '€0.00' },
5+
{ label: 'Shipping', value: '€0.00' },
6+
{ label: link_to('Add promo code', '#', class: "body-link"), value: '€0.00' },
7+
{ label: link_to('Adjustments', '#', class: "body-link"), value: '€0.00' },
8+
{ label: 'Total', value: '€90.00', class: 'font-semibold' }
9+
]
10+
) %>

0 commit comments

Comments
 (0)