mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-30 06:31:16 +00:00
Patching up our checkout flow so we don't try to create shipments before we have valid shipping addresses
This commit is contained in:
@@ -11,31 +11,27 @@ class Shop::CheckoutController < Spree::CheckoutController
|
||||
end
|
||||
|
||||
def update
|
||||
begin
|
||||
if @order.update_attributes(params[:order])
|
||||
fire_event('spree.checkout.update')
|
||||
if @order.update_attributes(params[:order])
|
||||
fire_event('spree.checkout.update')
|
||||
|
||||
while @order.state != "complete"
|
||||
if @order.next
|
||||
state_callback(:after)
|
||||
else
|
||||
flash[:error] = t(:payment_processing_failed)
|
||||
respond_with @order, location: main_app.shop_checkout_path
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if @order.state == "complete" || @order.completed?
|
||||
flash.notice = t(:order_processed_successfully)
|
||||
flash[:commerce_tracking] = "nothing special"
|
||||
respond_with(@order, :location => order_path(@order))
|
||||
while @order.state != "complete"
|
||||
if @order.next
|
||||
state_callback(:after)
|
||||
else
|
||||
flash[:error] = t(:payment_processing_failed)
|
||||
respond_with @order, location: main_app.shop_checkout_path
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if @order.state == "complete" || @order.completed?
|
||||
flash.notice = t(:order_processed_successfully)
|
||||
flash[:commerce_tracking] = "nothing special"
|
||||
respond_with(@order, :location => order_path(@order))
|
||||
else
|
||||
respond_with @order, location: main_app.shop_checkout_path
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
else
|
||||
respond_with @order, location: main_app.shop_checkout_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,6 +14,26 @@ Spree::Order.class_eval do
|
||||
|
||||
before_validation :shipping_address_from_distributor
|
||||
|
||||
checkout_flow do
|
||||
go_to_state :address
|
||||
go_to_state :delivery
|
||||
go_to_state :payment, :if => lambda { |order|
|
||||
if order.ship_address.andand.valid?
|
||||
# Fix for #2191
|
||||
if order.shipping_method
|
||||
order.create_shipment!
|
||||
order.update_totals
|
||||
end
|
||||
order.payment_required?
|
||||
else
|
||||
false
|
||||
end
|
||||
}
|
||||
go_to_state :confirm, :if => lambda { |order| order.confirmation_required? }
|
||||
go_to_state :complete, :if => lambda { |order| (order.payment_required? && order.has_unprocessed_payments?) || !order.payment_required? }
|
||||
remove_transition :from => :delivery, :to => :confirm
|
||||
end
|
||||
|
||||
|
||||
# -- Scopes
|
||||
scope :managed_by, lambda { |user|
|
||||
|
||||
Reference in New Issue
Block a user