From 0458f7a6bbfcfdc0d7240422eaae2f1c914e961d Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Mon, 19 Aug 2013 17:02:02 +1000 Subject: [PATCH] Summarise distribution fees in checkout after cart page --- app/helpers/checkout_helper.rb | 13 ++++++++ app/views/spree/checkout/_summary.html.erb | 36 ++++++++++++++++++++++ spec/features/consumer/checkout_spec.rb | 7 +++++ 3 files changed, 56 insertions(+) create mode 100644 app/helpers/checkout_helper.rb create mode 100644 app/views/spree/checkout/_summary.html.erb diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb new file mode 100644 index 0000000000..b21855bf7a --- /dev/null +++ b/app/helpers/checkout_helper.rb @@ -0,0 +1,13 @@ +module CheckoutHelper + def checkout_adjustments_for_summary(order) + adjustments = order.adjustments.eligible + + adjustments.reject! { |a| a.originator_type == 'Spree::TaxRate' && a.amount == 0 } + + enterprise_fee_adjustments = adjustments.select { |a| a.originator_type == 'EnterpriseFee' } + adjustments.reject! { |a| a.originator_type == 'EnterpriseFee' } + adjustments << Spree::Adjustment.new(label: 'Distribution', amount: enterprise_fee_adjustments.sum(&:amount)) + + adjustments + end +end diff --git a/app/views/spree/checkout/_summary.html.erb b/app/views/spree/checkout/_summary.html.erb new file mode 100644 index 0000000000..125254177e --- /dev/null +++ b/app/views/spree/checkout/_summary.html.erb @@ -0,0 +1,36 @@ + +

<%= t(:order_summary) %>

+ + + + + + + + + + <% adjustments = checkout_adjustments_for_summary(order) %> + <% adjustments.each do |adjustment| %> + + + + + <% end %> + + + + + + + <% if order.price_adjustment_totals.present? %> + + <% @order.price_adjustment_totals.each do |label, total| %> + + + + + <% end %> + + <% end %> + +
<%= t(:item_total) %>:<%= order.display_item_total %>
<%= adjustment.label %>: <%= adjustment.display_amount.to_html %>
<%= t(:order_total) %>:<%= @order.display_total.to_html %>
<%= label %><%= total %>
diff --git a/spec/features/consumer/checkout_spec.rb b/spec/features/consumer/checkout_spec.rb index d85ae84ef4..8a84df61a9 100644 --- a/spec/features/consumer/checkout_spec.rb +++ b/spec/features/consumer/checkout_spec.rb @@ -89,6 +89,13 @@ feature %q{ ['Product distribution by Edible garden for Garlic', '$2.00', '']] page.should have_selector 'span.distribution-total', :text => '$3.00' + + # When I check out + click_link 'Checkout' + + # Then I should see a summary of my distribution charges + page.should have_selector 'tbody#summary-order-charges td', text: 'Distribution:' + page.should have_selector 'tbody#summary-order-charges td', text: '$3.00' end scenario "viewing delivery fees for order cycle distribution" do