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:
parent
ee7fcbd2e4
commit
dc6bccfad3
|
@ -29,10 +29,11 @@ module Spree
|
||||||
def paypal_payment
|
def paypal_payment
|
||||||
load_order
|
load_order
|
||||||
opts = all_opts(@order, params[:payment_method_id], 'payment')
|
opts = all_opts(@order, params[:payment_method_id], 'payment')
|
||||||
unless payment_method.preferred_cart_checkout
|
|
||||||
opts.merge!(address_options(@order))
|
if payment_method.preferred_cart_checkout
|
||||||
else
|
|
||||||
opts.merge!(shipping_options)
|
opts.merge!(shipping_options)
|
||||||
|
else
|
||||||
|
opts.merge!(address_options(@order))
|
||||||
end
|
end
|
||||||
|
|
||||||
@gateway = paypal_gateway
|
@gateway = paypal_gateway
|
||||||
|
@ -297,13 +298,13 @@ module Spree
|
||||||
credits_total = credits.map {|i| i[:amount] * i[:quantity] }.sum
|
credits_total = credits.map {|i| i[:amount] * i[:quantity] }.sum
|
||||||
end
|
end
|
||||||
|
|
||||||
unless order.payment_method.preferred_cart_checkout
|
if payment_method.preferred_cart_checkout and (order.shipping_method.blank? or order.ship_total == 0)
|
||||||
order_total = (order.total * 100).to_i
|
shipping_cost = shipping_options[:shipping_options].first[:amount]
|
||||||
shipping_total = (order.ship_total*100).to_i
|
order_total = (order.total * 100 + (shipping_cost)).to_i
|
||||||
else
|
|
||||||
shipping_cost = shipping_options[:shipping_options].first[:amount]
|
|
||||||
order_total = (order.total * 100 + (shipping_cost)).to_i
|
|
||||||
shipping_total = (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
|
end
|
||||||
|
|
||||||
opts = { :return_url => paypal_confirm_order_checkout_url(order, :payment_method_id => payment_method_id),
|
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
|
#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
|
#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)
|
#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
|
opts[:handling] = 0
|
||||||
else
|
else
|
||||||
opts[:handling] = (order.total*100).to_i - opts.slice(:subtotal, :tax, :shipping).values.sum
|
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?
|
if spree_current_user.present? && spree_current_user.respond_to?(:addresses) && spree_current_user.addresses.present?
|
||||||
estimate_shipping_for_user
|
estimate_shipping_for_user
|
||||||
shipping_default = @rate_hash_user.map.with_index do |shipping_method, idx|
|
shipping_default = @rate_hash_user.map.with_index do |shipping_method, idx|
|
||||||
{ :default => (idx == 0 ? true : false),
|
if @order.shipping_method_id
|
||||||
:name => shipping_method.name,
|
default = (@order.shipping_method_id == shipping_method.id)
|
||||||
:amount => (shipping_method.cost*100).to_i }
|
else
|
||||||
|
default = (idx == 0)
|
||||||
|
end
|
||||||
|
{
|
||||||
|
:default => default,
|
||||||
|
:name => shipping_method.name,
|
||||||
|
:amount => (shipping_method.cost*100).to_i
|
||||||
|
}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
shipping_method = ShippingMethod.all.first
|
shipping_method = @order.shipping_method_id ? ShippingMethod.find(@order.shipping_method_id) : ShippingMethod.all.first
|
||||||
shipping_default = [{ :default => true,
|
shipping_default = [{ :default => true,
|
||||||
:name => shipping_method.name,
|
:name => shipping_method.name,
|
||||||
:amount => ((shipping_method.calculator.compute(@order).to_f) * 100).to_i }]
|
:amount => ((shipping_method.calculator.compute(self).to_f) * 100).to_i }]
|
||||||
end
|
end
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue