Use the state machine API to add state transition callbacks

See the following links for more context:
http://guides.spreecommerce.org/release_notes/spree_2_0_0.html#removal-of-checkoutcontrollerstatecallback
1d9581c884
This commit is contained in:
enricostano
2017-04-19 14:09:14 +02:00
committed by Rob Harrington
parent fd259e0a63
commit 4e35c0448b
2 changed files with 11 additions and 8 deletions

View File

@@ -170,14 +170,6 @@ class CheckoutController < Spree::CheckoutController
@order.ship_address ||= customer_preferred_ship_address || preferred_ship_address || last_used_ship_address || Spree::Address.default
end
def after_payment
# object_params sets the payment amount to the order total, but it does this before
# the shipping method is set. This results in the customer not being charged for their
# order's shipping. To fix this, we refresh the payment amount here.
@order.update_totals
@order.payments.first.update_attribute :amount, @order.total
end
# Overriding Spree's methods
def raise_insufficient_quantity
respond_to do |format|

View File

@@ -349,4 +349,15 @@ Spree::Order.class_eval do
adjustment.update!(self)
adjustment.locked = locked
end
# object_params sets the payment amount to the order total, but it does this before
# the shipping method is set. This results in the customer not being charged for their
# order's shipping. To fix this, we refresh the payment amount here.
def charge_shipping!
update_totals
return unless payments.any?
payments.first.update_attribute :amount, total
end
end
Spree::Order.state_machine.after_transition to: :payment, do: :charge_shipping!