mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
Handle order checkout responses with turbo_stream
This commit is contained in:
@@ -10,7 +10,6 @@ class CheckoutController < BaseController
|
||||
include CheckoutCallbacks
|
||||
include CheckoutSteps
|
||||
include OrderCompletion
|
||||
include CablecarResponses
|
||||
include WhiteLabel
|
||||
|
||||
helper 'terms_and_conditions'
|
||||
@@ -49,7 +48,7 @@ class CheckoutController < BaseController
|
||||
rescue Spree::Core::GatewayError => e
|
||||
flash[:error] = I18n.t(:spree_gateway_error_flash_for_checkout, error: e.message)
|
||||
@order.update_column(:state, "payment")
|
||||
render cable_ready: cable_car.redirect_to(url: checkout_step_path(:payment))
|
||||
redirect_to checkout_step_path(:payment)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -57,9 +56,12 @@ class CheckoutController < BaseController
|
||||
def render_error
|
||||
flash.now[:error] ||= I18n.t('checkout.errors.saving_failed')
|
||||
|
||||
render status: :unprocessable_entity, cable_ready: cable_car.
|
||||
replace("#checkout", partial("checkout/checkout")).
|
||||
replace("#flashes", partial("shared/flashes", locals: { flashes: flash }))
|
||||
respond_to do |format|
|
||||
format.html { head :unprocessable_entity }
|
||||
format.turbo_stream do
|
||||
render :render_error, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_payments_adjustments
|
||||
@@ -87,7 +89,7 @@ class CheckoutController < BaseController
|
||||
return unless selected_payment_method&.external_gateway?
|
||||
return unless (redirect_url = selected_payment_method.external_payment_url(order: @order))
|
||||
|
||||
render cable_ready: cable_car.redirect_to(url: redirect_url)
|
||||
redirect_to redirect_url
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module OrderStockCheck
|
||||
include CablecarResponses
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def valid_order_line_items?
|
||||
@@ -27,13 +26,7 @@ module OrderStockCheck
|
||||
current_order.set_order_cycle! nil
|
||||
|
||||
flash[:info] = I18n.t('order_cycle_closed')
|
||||
respond_to do |format|
|
||||
format.cable_ready {
|
||||
render status: :see_other, cable_ready: cable_car.redirect_to(url: main_app.shop_path)
|
||||
}
|
||||
format.json { render json: { path: main_app.shop_path }, status: :see_other }
|
||||
format.html { redirect_to main_app.shop_path, status: :see_other }
|
||||
end
|
||||
redirect_to main_app.shop_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -4,7 +4,6 @@ module Spree
|
||||
class OrdersController < ::BaseController
|
||||
include OrderCyclesHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
include CablecarResponses
|
||||
include WhiteLabel
|
||||
|
||||
layout 'darkswarm'
|
||||
@@ -107,8 +106,7 @@ module Spree
|
||||
else
|
||||
flash[:error] = I18n.t(:orders_could_not_cancel)
|
||||
end
|
||||
render status: :found,
|
||||
cable_ready: cable_car.redirect_to(url: request.referer || main_app.order_path(@order))
|
||||
redirect_to request.referer || main_app.order_path(@order)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= form_with url: checkout_update_path(checkout_step), model: @order, method: :put, data: { remote: "true" } do |f|
|
||||
= form_with url: checkout_update_path(checkout_step), model: @order, method: :put, data: { turbo: true } do |f|
|
||||
.medium-6
|
||||
= f.fields :bill_address, model: @order.bill_address do |bill_address|
|
||||
%div.checkout-substep
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
%div.checkout-substep
|
||||
= render partial: "checkout/voucher_section", locals: { order: @order, voucher_adjustment: @order.voucher_adjustments.first }
|
||||
|
||||
= form_with url: checkout_update_path(local_assigns[:step] || checkout_step), model: @order, method: :put, data: { remote: "true" } do |f|
|
||||
= form_with url: checkout_update_path(local_assigns[:step] || checkout_step), model: @order, method: :put, data: { turbo: "true" } do |f|
|
||||
%div.checkout-substep{"data-controller": "paymentmethod"}
|
||||
%div.checkout-title
|
||||
= t("checkout.step2.payment_method.title")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= form_with url: checkout_update_path(checkout_step), model: @order, method: :put, data: { remote: "true", 'guest-checkout-target': 'summary' } do |f|
|
||||
= form_with url: checkout_update_path(checkout_step), model: @order, method: :put, data: { turbo: "true", 'guest-checkout-target': 'summary' } do |f|
|
||||
.summary-main
|
||||
= render partial: "checkout/already_ordered" if show_bought_items? && checkout_step?(:summary)
|
||||
.checkout-substep
|
||||
|
||||
4
app/views/checkout/render_error.turbo_stream.haml
Normal file
4
app/views/checkout/render_error.turbo_stream.haml
Normal file
@@ -0,0 +1,4 @@
|
||||
= turbo_stream.replace "flashes" do
|
||||
= render(partial: 'shared/flashes', locals: { flashes: flash })
|
||||
= turbo_stream.replace "checkout" do
|
||||
= render(partial: 'checkout/checkout')
|
||||
Reference in New Issue
Block a user