mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
committed by
Rob Harrington
parent
fd259e0a63
commit
4e35c0448b
@@ -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|
|
||||
|
||||
@@ -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!
|
||||
|
||||
Reference in New Issue
Block a user