Checkout include distribution fees in cart total

This commit is contained in:
Rohan Mitchell
2014-08-07 14:47:49 +10:00
parent 591c3959f9
commit d1c9980f3f
2 changed files with 29 additions and 14 deletions

View File

@@ -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,

View File

@@ -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}