Fixes bugs where wrong payment method is referenced, and shipping has been already been applied when checking out from cart.

Conflicts:
	app/controllers/spree/checkout_controller_decorator.rb
This commit is contained in:
Jeff Dutil 2013-01-04 02:55:35 -05:00
parent ee7fcbd2e4
commit dc6bccfad3
1 changed files with 25 additions and 17 deletions

View File

@ -29,10 +29,11 @@ module Spree
def paypal_payment
load_order
opts = all_opts(@order, params[:payment_method_id], 'payment')
unless payment_method.preferred_cart_checkout
opts.merge!(address_options(@order))
else
if payment_method.preferred_cart_checkout
opts.merge!(shipping_options)
else
opts.merge!(address_options(@order))
end
@gateway = paypal_gateway
@ -297,13 +298,13 @@ module Spree
credits_total = credits.map {|i| i[:amount] * i[:quantity] }.sum
end
unless order.payment_method.preferred_cart_checkout
order_total = (order.total * 100).to_i
shipping_total = (order.ship_total*100).to_i
else
shipping_cost = shipping_options[:shipping_options].first[:amount]
order_total = (order.total * 100 + (shipping_cost)).to_i
if payment_method.preferred_cart_checkout and (order.shipping_method.blank? or order.ship_total == 0)
shipping_cost = shipping_options[:shipping_options].first[:amount]
order_total = (order.total * 100 + (shipping_cost)).to_i
shipping_total = (shipping_cost).to_i
else
order_total = (order.total * 100).to_i
shipping_total = (order.ship_total * 100).to_i
end
opts = { :return_url => paypal_confirm_order_checkout_url(order, :payment_method_id => payment_method_id),
@ -326,7 +327,7 @@ module Spree
#hack to add float rounding difference in as handling fee - prevents PayPal from rejecting orders
#because the integer totals are different from the float based total. This is temporary and will be
#removed once Spree's currency values are persisted as integers (normally only 1c)
if order.payment_method.preferred_cart_checkout
if payment_method.preferred_cart_checkout
opts[:handling] = 0
else
opts[:handling] = (order.total*100).to_i - opts.slice(:subtotal, :tax, :shipping).values.sum
@ -341,15 +342,22 @@ module Spree
if spree_current_user.present? && spree_current_user.respond_to?(:addresses) && spree_current_user.addresses.present?
estimate_shipping_for_user
shipping_default = @rate_hash_user.map.with_index do |shipping_method, idx|
{ :default => (idx == 0 ? true : false),
:name => shipping_method.name,
:amount => (shipping_method.cost*100).to_i }
if @order.shipping_method_id
default = (@order.shipping_method_id == shipping_method.id)
else
default = (idx == 0)
end
{
:default => default,
:name => shipping_method.name,
:amount => (shipping_method.cost*100).to_i
}
end
else
shipping_method = ShippingMethod.all.first
shipping_default = [{ :default => true,
:name => shipping_method.name,
:amount => ((shipping_method.calculator.compute(@order).to_f) * 100).to_i }]
shipping_method = @order.shipping_method_id ? ShippingMethod.find(@order.shipping_method_id) : ShippingMethod.all.first
shipping_default = [{ :default => true,
:name => shipping_method.name,
:amount => ((shipping_method.calculator.compute(self).to_f) * 100).to_i }]
end
{