<commit_before>class Shopping::BaseController < ApplicationController
  helper_method :session_order, :session_order_id
  # these are methods that can be used for all orders

  protected

  def ssl_required?
    ssl_supported?
  end

  private

  def next_form(order)

       # if cart is empty
    if session_cart.cart_items.empty?
      flash[:notice] = I18n.t('do_not_have_anything_in_your_cart')
      return root_url

       ## If we are insecure
    elsif not_secure?
      session[:return_to] = shopping_orders_url
      return login_url()
    elsif session_order.ship_address_id.nil?
      return shopping_addresses_url()
    elsif session_order.order_items.any?{ |item| item.shipping_rate_id.nil? }
      return shopping_shipping_methods_url()
    end
  end

  def not_secure?
    !current_user ||
    session[:authenticated_at].nil? ||
    (Time.now - session[:authenticated_at] > (60 * 20) ) || ## 20 minutes
    (cookies[:insecure].nil? || cookies[:insecure] == true)## this should happen every time the user goes to a non-SSL page
  end

  def session_order
    find_or_create_order
  end

  def session_order_id
    session[:order_id] ? session[:order_id] : find_or_create_order.id
  end

  def find_or_create_order
    return @session_order if @session_order
    if session[:order_id]
      @session_order = current_user.orders.includes([ {:ship_address => :state},
                                                      {:bill_address => :state},
                                                      {:order_items =>
                                                        {:variant =>
                                                          {:product => :images }}}]).find(session[:order_id])
      create_order if !@session_order.in_progress?
    else
      create_order
    end
    @session_order
  end

  def create_order
    @session_order = current_user.orders.create(:number       => Time.now.to_i,<commit_msg>clean up methods in shopping checkout<commit_after>class Shopping::BaseController < ApplicationController
  helper_method :session_order, :session_order_id
  # these are methods that can be used for all orders

  protected

  def ssl_required?
    ssl_supported?
  end

  private

  def next_form(order)

    # if cart is empty
    if session_cart.cart_items.empty?
      flash[:notice] = I18n.t('do_not_have_anything_in_your_cart')
      return root_url
    ## If we are insecure
    elsif not_secure?
      session[:return_to] = shopping_orders_url
      return login_url()
    elsif session_order.ship_address_id.nil?
      return shopping_addresses_url()
    elsif session_order.all_order_items_have_a_shipping_rate?
      return shopping_shipping_methods_url()
    end
  end

  def not_secure?
    !current_user || has_not_logged_in_recently? || user_visited_a_non_ssl_page_since_login?
  end

  def has_not_logged_in_recently?(minutes = 20)
    session[:authenticated_at].nil? || Time.now - session[:authenticated_at] > (60 * minutes)
  end

  ## this should happen every time the user goes to a non-SSL page
  def user_visited_a_non_ssl_page_since_login?
    cookies[:insecure].nil? || cookies[:insecure] == true
  end

  def session_order
    find_or_create_order
  end

  def session_order_id
    session[:order_id] ? session[:order_id] : find_or_create_order.id
  end

  def find_or_create_order
    return @session_order if @session_order
    if session[:order_id]
      @session_order = current_user.orders.includes([ {:ship_address => :state},
                                                      {:bill_address => :state},
                                                      {:order_items =>
                                                        {:variant =>
                                                          {:product => :images }}}]).find(session[:order_id])
      create_order if !@session_order.in_progress?
    else
      create_order
    end
    @session_order
  end

  def create_order
    @session_order = current_user.orders.create(:number       => Time.now.to_i,
{'fraction_non_alphanumeric': 0.08254833911750124, 'fraction_numerical': 0.0034705007436787306, 'mean_word_length': 2.419491525423729, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '358872', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1150, 'n_words': 257}