From 8a3bffb37d69293ffc02967f80bf3d54de142b7c Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 26 Nov 2014 18:53:29 +1100 Subject: [PATCH] Cart page conforms to convention in rest of checkout, adjusting helpers through checkout --- .../javascripts/darkswarm/cart.js.coffee | 3 +-- app/helpers/checkout_helper.rb | 20 +++++++++++++------ app/helpers/spree/orders_helper.rb | 6 ------ app/views/checkout/_summary.html.haml | 4 ++-- .../confirm_email_for_customer.html.haml | 4 ++-- .../confirm_email_for_shop.html.haml | 4 ++-- app/views/spree/orders/_adjustments.html.haml | 4 ++-- app/views/spree/orders/_form.html.haml | 8 ++++---- app/views/spree/orders/_line_item.html.haml | 4 ++-- .../spree/shared/_order_details.html.haml | 4 ++-- 10 files changed, 31 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/darkswarm/cart.js.coffee b/app/assets/javascripts/darkswarm/cart.js.coffee index bb68d0d7ec..cd12c67c4a 100644 --- a/app/assets/javascripts/darkswarm/cart.js.coffee +++ b/app/assets/javascripts/darkswarm/cart.js.coffee @@ -13,8 +13,7 @@ $ -> $(document).ready -> $('#cart_adjustments').hide() - $('th.cart-adjustment-header').html('Distribution...') $('th.cart-adjustment-header a').click -> $('#cart_adjustments').toggle() - $('th.cart-adjustment-header a').html('Distribution') + $(this).html('Item Handling Fees (included in item totals)') false diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index b6c43bc412..cd986eb565 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -1,5 +1,5 @@ module CheckoutHelper - def checkout_adjustments_for_summary(order, opts={}) + def checkout_adjustments_for(order, opts={}) adjustments = order.adjustments.eligible exclude = opts[:exclude] || {} @@ -8,8 +8,8 @@ module CheckoutHelper adjustments.reject! { |a| a.originator_type == 'Spree::ShippingMethod' } if exclude.include? :shipping adjustments.reject! { |a| a.source_type == 'Spree::LineItem' } if exclude.include? :line_item - enterprise_fee_adjustments = adjustments.select { |a| a.originator_type == 'EnterpriseFee' } - adjustments.reject! { |a| a.originator_type == 'EnterpriseFee' } + enterprise_fee_adjustments = adjustments.select { |a| a.originator_type == 'EnterpriseFee' && a.source_type != 'Spree::LineItem' } + adjustments.reject! { |a| a.originator_type == 'EnterpriseFee' && a.source_type != 'Spree::LineItem' } unless exclude.include? :admin_and_handling adjustments << Spree::Adjustment.new(label: 'Admin & Handling', amount: enterprise_fee_adjustments.sum(&:amount)) end @@ -17,13 +17,21 @@ module CheckoutHelper adjustments end + def display_checkout_admin_and_handling_adjustments_total_for(order) + adjustments = order.adjustments.eligible.where('originator_type = ? AND source_type != ? ', 'EnterpriseFee', 'Spree::LineItem' ) + Spree::Money.new( adjustments.sum( &:amount ) , { :currency => order.currency }) + end + def checkout_line_item_adjustments(order) - adjustments = order.adjustments.eligible.where( source_type: "Spree::LineItem") - Spree::Money.new( adjustments.sum(&:amount) , { :currency => order.currency }) + order.adjustments.eligible.where( source_type: "Spree::LineItem") end def checkout_subtotal(order) - order.display_item_total.money.to_f + checkout_line_item_adjustments(order).money.to_f + order.item_total + checkout_line_item_adjustments(order).sum( &:amount ) + end + + def display_checkout_subtotal(order) + Spree::Money.new( checkout_subtotal(order) , { :currency => order.currency }) end def checkout_state_options(source_address) diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 93b59c8e4b..5fd0f74fa8 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -5,12 +5,6 @@ module Spree order.nil? || order.line_items.empty? end - def order_distribution_subtotal(order, options={}) - options.reverse_merge! :format_as_currency => true - amount = order.adjustments.enterprise_fee.sum &:amount - options.delete(:format_as_currency) ? spree_number_to_currency(amount) : amount - end - def alternative_available_distributors(order) DistributionChangeValidator.new(order).available_distributors(Enterprise.all) - [order.distributor] end diff --git a/app/views/checkout/_summary.html.haml b/app/views/checkout/_summary.html.haml index d07a097db6..5bdd13187b 100644 --- a/app/views/checkout/_summary.html.haml +++ b/app/views/checkout/_summary.html.haml @@ -5,9 +5,9 @@ %table %tr %th Cart total - %td.cart-total.text-right= spree_number_to_currency checkout_subtotal(@order) + %td.cart-total.text-right= display_checkout_subtotal(@order) - - checkout_adjustments_for_summary(current_order, exclude: [:shipping, :line_item]).reject{ |a| a.amount == 0 }.each do |adjustment| + - checkout_adjustments_for(current_order, exclude: [:shipping, :line_item]).reject{ |a| a.amount == 0 }.each do |adjustment| %tr %th= adjustment.label %td.text-right= adjustment.display_amount.to_html diff --git a/app/views/spree/order_mailer/confirm_email_for_customer.html.haml b/app/views/spree/order_mailer/confirm_email_for_customer.html.haml index 9c0b57c3b2..49f23087ed 100644 --- a/app/views/spree/order_mailer/confirm_email_for_customer.html.haml +++ b/app/views/spree/order_mailer/confirm_email_for_customer.html.haml @@ -47,8 +47,8 @@ %td{:align => "right", :colspan => "2"} Subtotal: %td{:align => "right"} - = spree_number_to_currency checkout_subtotal(@order) - - checkout_adjustments_for_summary(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| + = display_checkout_subtotal(@order) + - checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| %tr %td{:align => "right", :colspan => "2"} = "#{raw(adjustment.label)}:" diff --git a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml index 9c0b57c3b2..49f23087ed 100644 --- a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml +++ b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml @@ -47,8 +47,8 @@ %td{:align => "right", :colspan => "2"} Subtotal: %td{:align => "right"} - = spree_number_to_currency checkout_subtotal(@order) - - checkout_adjustments_for_summary(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| + = display_checkout_subtotal(@order) + - checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| %tr %td{:align => "right", :colspan => "2"} = "#{raw(adjustment.label)}:" diff --git a/app/views/spree/orders/_adjustments.html.haml b/app/views/spree/orders/_adjustments.html.haml index 21e971832a..71579e3ace 100644 --- a/app/views/spree/orders/_adjustments.html.haml +++ b/app/views/spree/orders/_adjustments.html.haml @@ -1,10 +1,10 @@ %thead %tr{"data-hook" => "cart_adjustments_headers"} %th.cart-adjustment-header{colspan: "6"} - Distribution Fees + %a{ href: "#" } Fees... %tbody#cart_adjustments{"data-hook" => ""} - - @order.adjustments.eligible.each do |adjustment| + - checkout_line_item_adjustments(@order).each do |adjustment| %tr %td{colspan: "4"}= adjustment.label %td= adjustment.display_amount.to_html diff --git a/app/views/spree/orders/_form.html.haml b/app/views/spree/orders/_form.html.haml index 953ea83e18..435ff03ff6 100644 --- a/app/views/spree/orders/_form.html.haml +++ b/app/views/spree/orders/_form.html.haml @@ -22,13 +22,13 @@ %tfoot#edit-cart %tr %td - Product + Produce Subtotal \: - %span.order-total.item-total= spree_number_to_currency(@order.item_total) + %span.order-total.item-total= display_checkout_subtotal(@order) %td - Distribution + Admin & Handling \: - %span.order-total.distribution-total= order_distribution_subtotal(@order) + %span.order-total.distribution-total= display_checkout_admin_and_handling_adjustments_total_for(@order) %td %td = button_tag :class => 'secondary radius expand small', :id => 'update-button' do diff --git a/app/views/spree/orders/_line_item.html.haml b/app/views/spree/orders/_line_item.html.haml index 59db1c6878..027e16978a 100644 --- a/app/views/spree/orders/_line_item.html.haml +++ b/app/views/spree/orders/_line_item.html.haml @@ -14,11 +14,11 @@ %br/ %td.cart-item-price{"data-hook" => "cart_item_price"} - = line_item.single_money.to_html + = line_item.single_display_amount_with_adjustments.to_html %td.cart-item-quantity{"data-hook" => "cart_item_quantity"} = item_form.number_field :quantity, :min => 0, :class => "line_item_quantity", :size => 5 %td.cart-item-total{"data-hook" => "cart_item_total"} - = line_item.display_amount.to_html unless line_item.quantity.nil? + = line_item.display_amount_with_adjustments.to_html unless line_item.quantity.nil? %td.cart-item-delete.text-center{"data-hook" => "cart_item_delete"} {{ quantity }} diff --git a/app/views/spree/shared/_order_details.html.haml b/app/views/spree/shared/_order_details.html.haml index 7e72432f6f..a3308ced34 100644 --- a/app/views/spree/shared/_order_details.html.haml +++ b/app/views/spree/shared/_order_details.html.haml @@ -84,10 +84,10 @@ %b Produce: %td.total - %span= checkout_subtotal(@order) + %span= display_checkout_subtotal(@order) %tfoot#order-charges{"data-hook" => "order_details_adjustments"} - - checkout_adjustments_for_summary(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| + - checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| %tr.total %td{:colspan => "4"} %strong= adjustment.label + ":"