Files
openfoodnetwork/app/controllers/concerns/order_stock_check.rb
Matt-Yorkley 96f30133a7 Don't reset order for split checkout
The various places where we "reset" an order to cart state if a checkout submission does not succeed are an artifact of the process-all-the-steps-at-once approach of the current checkout.
2022-01-14 19:41:08 +00:00

33 lines
738 B
Ruby

# frozen_string_literal: true
module OrderStockCheck
extend ActiveSupport::Concern
def valid_order_line_items?
@order.insufficient_stock_lines.empty? &&
OrderCycleDistributedVariants.new(@order.order_cycle, @order.distributor).
distributes_order_variants?(@order)
end
def handle_insufficient_stock
return if sufficient_stock?
reset_order_to_cart
flash[:error] = Spree.t(:inventory_error_flash_for_insufficient_quantity)
redirect_to main_app.cart_path
end
private
def sufficient_stock?
@sufficient_stock ||= @order.insufficient_stock_lines.blank?
end
def reset_order_to_cart
return if Flipper.enabled? :split_checkout
OrderCheckoutRestart.new(@order).call
end
end