From d1c9980f3fbb2483357acc6dfe6586851329bd74 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 7 Aug 2014 14:47:49 +1000 Subject: [PATCH] Checkout include distribution fees in cart total --- app/helpers/checkout_helper.rb | 17 +++++++++++++++-- app/views/checkout/_summary.html.haml | 26 ++++++++++++++------------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index 5faccb781d..171a672cda 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -1,18 +1,31 @@ module CheckoutHelper def checkout_adjustments_for_summary(order, opts={}) adjustments = order.adjustments.eligible + exclude = opts[:exclude] || {} # Remove empty tax adjustments and (optionally) shipping fees adjustments.reject! { |a| a.originator_type == 'Spree::TaxRate' && a.amount == 0 } - adjustments.reject! { |a| a.originator_type == 'Spree::ShippingMethod' } if opts[:exclude_shipping] + adjustments.reject! { |a| a.originator_type == 'Spree::ShippingMethod' } if exclude.include? :shipping 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)) + unless exclude.include? :distribution + adjustments << Spree::Adjustment.new(label: 'Distribution', amount: enterprise_fee_adjustments.sum(&:amount)) + end adjustments end + def checkout_adjustments_total(order) + adjustments = checkout_adjustments_for_summary(order, exclude: [:shipping]) + adjustments.sum &:display_amount + end + + def checkout_cart_total_with_adjustments(order) + current_order.display_item_total.money.to_f + checkout_adjustments_total(current_order).money.to_f + end + + def validated_input(name, path, args = {}) attributes = { required: true, diff --git a/app/views/checkout/_summary.html.haml b/app/views/checkout/_summary.html.haml index bc0a0e307f..0e03af7413 100644 --- a/app/views/checkout/_summary.html.haml +++ b/app/views/checkout/_summary.html.haml @@ -5,23 +5,25 @@ %table %tr %th Cart total - %td.text-right= current_order.display_item_total + %td.cart-total.text-right= number_to_currency checkout_cart_total_with_adjustments(current_order) + + - checkout_adjustments_for_summary(current_order, exclude: [:shipping, :distribution]).each do |adjustment| + %tr + %th= adjustment.label + %td.text-right= adjustment.display_amount.to_html - / - checkout_adjustments_for_summary(current_order, exclude_shipping: true).each do |adjustment| - / %tr - / %th= adjustment.label - / %td.text-right= adjustment.display_amount.to_html %tr %th Shipping - %td.text-right {{ Checkout.shippingPrice() | currency }} + %td.shipping.text-right {{ Checkout.shippingPrice() | currency }} + %tr %th Total - %td.text-right {{ Checkout.cartTotal() | currency }} - / - if current_order.price_adjustment_totals.present? - / - current_order.price_adjustment_totals.each do |label, total| - / %tr - / %th= label - / %td= total + %td.total.text-right {{ Checkout.cartTotal() | currency }} + - if current_order.price_adjustment_totals.present? + - current_order.price_adjustment_totals.each do |label, total| + %tr + %th= label + %td= total //= f.submit "Purchase", class: "button", "ng-disabled" => "checkout.$invalid", "ofn-focus" => "accordion['payment']" %a.button.secondary{href: cart_url}