-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
e8cd2d4
commit 7a32cb6
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
admin/app/components/solidus_admin/orders/show/summary/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="<%= stimulus_id %> w-full"> | ||
<%= render component('ui/panel').new(title: t('.summary')) do %> | ||
<%= render component('ui/details_list').new( | ||
items: [ | ||
{ label: t('.subtotal'), value: number_to_currency(@order.item_total), class: 'font-semibold' }, | ||
{ label: t('.taxes'), value: number_to_currency(@order.additional_tax_total) }, | ||
{ label: t('.shipping'), value: number_to_currency(@order.shipment_total) }, | ||
{ label: link_to(t('.add_promo_code'), '#', class: "body-link"), value: number_to_currency(@order.promo_total) }, | ||
{ label: link_to(t('.adjustments'), '#', class: "body-link"), value: number_to_currency(@order.adjustment_total) }, | ||
{ label: t('.total'), value: number_to_currency(@order.total), class: 'font-semibold' } | ||
] | ||
) %> | ||
<% end %> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
admin/app/components/solidus_admin/orders/show/summary/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Orders::Show::Summary::Component < SolidusAdmin::BaseComponent | ||
def initialize(order:) | ||
@order = order | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
admin/app/components/solidus_admin/orders/show/summary/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
en: | ||
summary: Summary | ||
subtotal: Subtotal | ||
taxes: Taxes | ||
shipping: Shipping | ||
add_promo_code: Add Promo Code | ||
adjustments: Adjustments | ||
total: Total |
45 changes: 45 additions & 0 deletions
45
admin/spec/components/previews/solidus_admin/orders/show/summary/component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
# @component "orders/show/summary" | ||
class SolidusAdmin::Orders::Show::Summary::ComponentPreview < ViewComponent::Preview | ||
include SolidusAdmin::Preview | ||
|
||
def overview | ||
order = fake_order(item_total: 340, additional_tax_total: 10, shipment_total: 20, promo_total: 10, adjustment_total: 20) | ||
render_with_template(locals: { order: order }) | ||
end | ||
|
||
# @param item_total [Float] | ||
# @param additional_tax_total [Float] | ||
# @param shipment_total [Float] | ||
# @param promo_total [Float] | ||
# @param adjustment_total [Float] | ||
def playground(item_total: 100, additional_tax_total: 10, shipment_total: 5, promo_total: 0, adjustment_total: 0) | ||
fake_order = fake_order( | ||
item_total: item_total, | ||
additional_tax_total: additional_tax_total, | ||
shipment_total: shipment_total, | ||
promo_total: promo_total, | ||
adjustment_total: adjustment_total | ||
) | ||
|
||
render current_component.new(order: fake_order) | ||
end | ||
|
||
private | ||
|
||
def fake_order(item_total:, additional_tax_total:, shipment_total:, promo_total:, adjustment_total:) | ||
order = Spree::Order.new | ||
|
||
order.define_singleton_method(:item_total) { item_total } | ||
order.define_singleton_method(:additional_tax_total) { additional_tax_total } | ||
order.define_singleton_method(:shipment_total) { shipment_total } | ||
order.define_singleton_method(:promo_total) { promo_total } | ||
order.define_singleton_method(:adjustment_total) { adjustment_total } | ||
order.define_singleton_method(:total) { | ||
item_total.to_f + additional_tax_total.to_f + shipment_total.to_f - promo_total.to_f - adjustment_total.to_f | ||
} | ||
|
||
order | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
...components/previews/solidus_admin/orders/show/summary/component_preview/overview.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render current_component.new(order: order) %> |
9 changes: 9 additions & 0 deletions
9
admin/spec/components/solidus_admin/orders/show/summary/component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe SolidusAdmin::Orders::Show::Summary::Component, type: :component do | ||
it "renders the overview preview" do | ||
render_preview(:overview) | ||
end | ||
end |