<commit_before># 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

  def check_order_cycle_expiry
    return unless current_order_cycle&.closed?

    Bugsnag.notify("Notice: order cycle closed during checkout completion", order: current_order)
    current_order.empty!
    current_order.set_order_cycle! nil

    flash[:info] = I18n.t('order_cycle_closed')
    redirect_to main_app.shop_path
  end

  private

  def sufficient_stock?
    @sufficient_stock ||= @order.insufficient_stock_lines.blank?
  end
<commit_msg>Redirect to shop front when OC closes during checkout<commit_after># 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

  def check_order_cycle_expiry
    return unless current_order_cycle&.closed?

    Bugsnag.notify("Notice: order cycle closed during checkout completion", order: current_order)
    current_order.empty!
    current_order.set_order_cycle! nil

    flash[:info] = I18n.t('order_cycle_closed')
    respond_to do |format|
      format.json { render json: { path: main_app.shop_path }, status: :see_other }
      format.html { redirect_to main_app.shop_path, status: :see_other }
    end
  end

  private

  def sufficient_stock?
    @sufficient_stock ||= @order.insufficient_stock_lines.blank?
  end

{'fraction_non_alphanumeric': 0.07533926064576509, 'fraction_numerical': 0.0018717828731867104, 'mean_word_length': 4.656084656084656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4431668', 'n_tokens_mistral': 697, 'n_tokens_neox': 665, 'n_words': 128}