Make cost breakdowns consistent throughout checkout

This commit is contained in:
Rob Harrington
2014-11-26 13:07:40 +11:00
parent c4961d2502
commit f6b0863279
7 changed files with 58 additions and 28 deletions

View File

@@ -53,6 +53,10 @@ table.social
background-color: white!important
border: 1px solid #ebebeb
table.order-summary
border-collapse: separate
border-spacing: 0px 10px
.social .soc-btn
padding: 3px 7px
font-size: 12px

View File

@@ -6,23 +6,24 @@ module CheckoutHelper
# 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 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' }
unless exclude.include? :distribution
adjustments << Spree::Adjustment.new(label: 'Distribution', amount: enterprise_fee_adjustments.sum(&:amount))
unless exclude.include? :admin_and_handling
adjustments << Spree::Adjustment.new(label: 'Admin & Handling', 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
def checkout_line_item_adjustments(order)
adjustments = order.adjustments.eligible.where( source_type: "Spree::LineItem")
Spree::Money.new( adjustments.sum(&:amount) , { :currency => order.currency })
end
def checkout_cart_total_with_adjustments(order)
order.display_item_total.money.to_f + checkout_adjustments_total(order).money.to_f
def checkout_subtotal(order)
order.display_item_total.money.to_f + checkout_line_item_adjustments(order).money.to_f
end
def checkout_state_options(source_address)
@@ -47,9 +48,9 @@ module CheckoutHelper
name: path,
id: path,
"ng-model" => path,
"ng-class" => "{error: !fieldValid('#{path}')}"
"ng-class" => "{error: !fieldValid('#{path}')}"
}.merge args
render "shared/validated_input", name: name, path: path, attributes: attributes
end

View File

@@ -23,10 +23,20 @@ Spree::LineItem.class_eval do
where('spree_products.supplier_id IN (?)', enterprises)
}
def price_with_adjustments
# EnterpriseFee#create_locked_adjustment applies adjustments on line items to their parent order,
# so line_item.adjustments returns an empty array
price + order.adjustments.where(source_id: id).sum(&:amount) / quantity
end
def single_display_amount_with_adjustments
Spree::Money.new(price_with_adjustments, { :currency => currency })
end
def amount_with_adjustments
# EnterpriseFee#create_locked_adjustment applies adjustments on line items to their parent order,
# so line_item.adjustments returns an empty array
amount + Spree::Adjustment.where(source_id: id).sum(&:amount)
amount + order.adjustments.where(source_id: id).sum(&:amount)
end
def display_amount_with_adjustments

View File

@@ -5,11 +5,11 @@
%table
%tr
%th Cart total
%td.cart-total.text-right= spree_number_to_currency(checkout_cart_total_with_adjustments(current_order))
%td.cart-total.text-right= spree_number_to_currency checkout_subtotal(@order)
- checkout_adjustments_for_summary(current_order, exclude: [:shipping, :distribution]).each do |adjustment|
- checkout_adjustments_for_summary(current_order, exclude: [:shipping, :line_item]).reject{ |a| a.amount == 0 }.each do |adjustment|
%tr
%th= adjustment.label
%th= adjustment.label
%td.text-right= adjustment.display_amount.to_html
%tr
@@ -17,7 +17,7 @@
%td.shipping.text-right {{ Checkout.shippingPrice() | localizeCurrency }}
%tr
%th Total
%th Total
%td.total.text-right {{ Checkout.cartTotal() | localizeCurrency }}
- if current_order.price_adjustment_totals.present?
- current_order.price_adjustment_totals.each do |label, total|
@@ -26,7 +26,7 @@
%td= total
//= f.submit "Purchase", class: "button", "ofn-focus" => "accordion['payment']"
%a.button.secondary{href: cart_url}
%a.button.secondary{href: cart_url}
%i.ofn-i_008-caret-left
Back to Cart

View File

@@ -47,11 +47,11 @@
%td{:align => "right", :colspan => "2"}
Subtotal:
%td{:align => "right"}
= spree_number_to_currency checkout_cart_total_with_adjustments(@order)
- checkout_adjustments_for_summary(@order, exclude: [:distribution]).reject{ |a| a.amount == 0 }.each do |adjustment|
= spree_number_to_currency checkout_subtotal(@order)
- checkout_adjustments_for_summary(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment|
%tr
%td{:align => "right", :colspan => "2"}
= raw(adjustment.label)
= "#{raw(adjustment.label)}:"
%td{:align => "right"}
= adjustment.display_amount
%tr
@@ -83,14 +83,17 @@
- if @order.shipping_method.andand.description
#{@order.shipping_method.description.html_safe}
%br
%br
- if @order.order_cycle.andand.pickup_time_for(@order.distributor)
Delivery on: #{@order.order_cycle.pickup_time_for(@order.distributor)}
%br
%br
- if @order.order_cycle.andand.pickup_instructions_for(@order.distributor)
Other delivery information: #{@order.order_cycle.pickup_instructions_for(@order.distributor)}
%br
%br
- else
@@ -102,18 +105,22 @@
- if @order.shipping_method.andand.description
= @order.shipping_method.description.html_safe
%br
%br
- if @order.order_cycle.andand.pickup_time_for(@order.distributor)
Ready for collection: #{@order.order_cycle.pickup_time_for(@order.distributor)}
%br
%br
- if @order.order_cycle.andand.pickup_instructions_for(@order.distributor)
Collection instructions: #{@order.order_cycle.pickup_instructions_for(@order.distributor)}
%br
%br
- if @order.special_instructions.present?
Notes: #{@order.special_instructions}
%br
%br
-# Your order will be ready for collection on
-# %strong{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"}

View File

@@ -10,7 +10,7 @@
%p
Thanks for shopping on
%strong= "#{Spree::Config.site_name}."
Here are your order details from
Here are the details for you order from
%strong= "#{@order.distributor.name}."
%table.column{:align => "left"}
%tr
@@ -39,18 +39,19 @@
%td{:align => "right"}
= item.quantity
%td{:align => "right"}
= item.display_amount
= item.display_amount_with_adjustments
%tr
%td{:colspan => "3"} &nbsp;
%tr
%td{:align => "right", :colspan => "2"}
Subtotal:
%td{:align => "right"}
= spree_number_to_currency checkout_cart_total_with_adjustments(@order)
- checkout_adjustments_for_summary(@order, exclude: [:distribution]).reject{ |a| a.amount == 0 }.each do |adjustment|
= spree_number_to_currency checkout_subtotal(@order)
- checkout_adjustments_for_summary(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment|
%tr
%td{:align => "right", :colspan => "2"}
= raw(adjustment.label)
= "#{raw(adjustment.label)}:"
%td{:align => "right"}
= adjustment.display_amount
%tr
@@ -82,14 +83,17 @@
- if @order.shipping_method.andand.description
#{@order.shipping_method.description.html_safe}
%br
%br
- if @order.order_cycle.andand.pickup_time_for(@order.distributor)
Delivery on: #{@order.order_cycle.pickup_time_for(@order.distributor)}
%br
%br
- if @order.order_cycle.andand.pickup_instructions_for(@order.distributor)
Other delivery information: #{@order.order_cycle.pickup_instructions_for(@order.distributor)}
%br
%br
- else
@@ -101,18 +105,22 @@
- if @order.shipping_method.andand.description
= @order.shipping_method.description.html_safe
%br
%br
- if @order.order_cycle.andand.pickup_time_for(@order.distributor)
Ready for collection: #{@order.order_cycle.pickup_time_for(@order.distributor)}
%br
%br
- if @order.order_cycle.andand.pickup_instructions_for(@order.distributor)
Collection instructions: #{@order.order_cycle.pickup_instructions_for(@order.distributor)}
%br
%br
- if @order.special_instructions.present?
Notes: #{@order.special_instructions}
%br
%br
-# Your order will be ready for collection on
-# %strong{:style => "margin: 0;padding: 0;font-family: \"Helvetica Neue\", \"Helvetica\", Helvetica, Arial, sans-serif;"}

View File

@@ -53,10 +53,10 @@
= truncated_product_description(item.variant.product)
= "(" + item.variant.options_text + ")" unless item.variant.option_values.empty?
%td.price{"data-hook" => "order_item_price"}
%span= item.single_money.to_html
%span= item.single_display_amount_with_adjustments.to_html
%td{"data-hook" => "order_item_qty"}= item.quantity
%td.total{"data-hook" => "order_item_total"}
%span= item.display_amount.to_html
%span= item.display_amount_with_adjustments.to_html
%tfoot#order-total{"data-hook" => "order_details_total"}
%tr.total
@@ -82,12 +82,12 @@
%tr#subtotal-row.total
%td{colspan: "4"}
%b
Produce:
Produce:
%td.total
%span= @order.display_item_total.to_html
%span= checkout_subtotal(@order)
%tfoot#order-charges{"data-hook" => "order_details_adjustments"}
- checkout_adjustments_for_summary(@order).reverse_each do |adjustment|
- checkout_adjustments_for_summary(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment|
%tr.total
%td{:colspan => "4"}
%strong= adjustment.label + ":"