mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
add redirection to correct step
This commit is contained in:
committed by
Jean-Baptiste Bellet
parent
87a0a5846d
commit
0ea968a900
@@ -1,15 +1,17 @@
|
||||
class SplitCheckoutController < CheckoutController
|
||||
def edit
|
||||
redirect_to_step if request.path == "/checkout"
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
byebug
|
||||
params_adapter = Checkout::FormDataAdapter.new(permitted_params, @order, spree_current_user)
|
||||
return action_failed unless @order.update(params_adapter.params[:order] || {})
|
||||
|
||||
checkout_workflow(params_adapter.shipping_method_id, params[:advance_to_state] || "delivery")
|
||||
rescue Spree::Core::GatewayError => e
|
||||
byebug
|
||||
rescue_from_spree_gateway_error(e)
|
||||
rescue StandardError => e
|
||||
byebug
|
||||
flash[:error] = I18n.t("checkout.failed")
|
||||
action_failed(e)
|
||||
ensure
|
||||
@@ -18,9 +20,25 @@ class SplitCheckoutController < CheckoutController
|
||||
|
||||
private
|
||||
|
||||
def redirect_to_step
|
||||
if @order.state = "payment"
|
||||
if @order.payment_method_id.nil?
|
||||
redirect_to checkout_payment_method_path
|
||||
else
|
||||
redirect_to checkout_order_summary_path
|
||||
end
|
||||
elsif @order.state == "cart"
|
||||
redirect_to checkout_your_details_path
|
||||
end
|
||||
end
|
||||
|
||||
def redirect_to_payment_gateway
|
||||
return unless params&.dig(:order)&.dig(:payments_attributes)&.first&.dig(:payments_attributes)
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def update_response
|
||||
redirect_to checkout_payment_method_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,6 +72,9 @@ Openfoodnetwork::Application.routes.draw do
|
||||
constraints(SplitCheckoutConstraint.new) do
|
||||
get '/checkout', to: 'split_checkout#edit', as: :checkout
|
||||
put '/checkout', to: 'split_checkout#update', as: :update_checkout
|
||||
get '/checkout/enter-your-details', to: 'split_checkout#edit', as: :checkout_your_details
|
||||
get '/checkout/payment-method', to: 'split_checkout#edit', as: :checkout_payment_method
|
||||
get '/checkout/order-summary', to: 'split_checkout#edit', as: :checkout_summary
|
||||
get '/checkout/:state', to: 'split_checkout#edit', as: :checkout_state
|
||||
get '/checkout/paypal_payment/:order_id', to: 'split_checkout#paypal_payment', as: :paypal_payment
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user