mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Cart page conforms to convention in rest of checkout, adjusting helpers through checkout
This commit is contained in:
@@ -13,8 +13,7 @@ $ ->
|
||||
$(document).ready ->
|
||||
$('#cart_adjustments').hide()
|
||||
|
||||
$('th.cart-adjustment-header').html('<a href="#">Distribution...</a>')
|
||||
$('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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)}:"
|
||||
|
||||
@@ -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)}:"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -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 + ":"
|
||||
|
||||
Reference in New Issue
Block a user