<commit_before>Spree::CheckoutController.class_eval do
  after_action :check_backorder_and_shipment_categories
  def ensure_checkout_allowed
    check = @order.checkout_allowed?
    unless check == true
      redirect_to spree.root_path, :flash => {:notice => I18n.t("checkout_allowed_errors.#{check}") + Spree::Config[:minimum_order_value] + " " + Spree::Config[:currency]}
    end
  end

  private

    def check_backorder_and_shipment_categories
      return unless params[:state] == "delivery"
      if Spree::Config[:backorder_charge] || Spree::Config[:check_categories]
        @order.shipments.each do |shipment|
          if shipment.backordered? && Spree::Config[:backorder_charge]
            shipment.update_column(:cost, 0)
          end
          if @order.shipments.count > 1 && shipment.id != @order.shipments.first.id && Spree::Config[:check_categories]
              shipment.update_column(:cost, 0)
          end
        end
        @order.reload.update!
      end
    end

    def check_registration
      return unless Spree::Auth::Config[:registration_step]
      return if spree_current_user or current_order.email
      store_location
      redirect_to spree.signup_path
    end

     def before_address
        # if the user has a default address, a callback takes care of setting
        # that; but if he doesn't, we need to build an empty one here
        @order.bill_address = spree_current_user.bill_address || Address.build_default
        @order.ship_address = spree_current_user.ship_address || Address.build_default if @order.checkout_steps.include?('delivery')
    end
end
<commit_msg>bug on checkout with user not logged<commit_after>Spree::CheckoutController.class_eval do
  after_action :check_backorder_and_shipment_categories
  def ensure_checkout_allowed
    check = @order.checkout_allowed?
    unless check == true
      redirect_to spree.root_path, :flash => {:notice => I18n.t("checkout_allowed_errors.#{check}") + Spree::Config[:minimum_order_value] + " " + Spree::Config[:currency]}
    end
  end

  private

    def check_backorder_and_shipment_categories
      return unless params[:state] == "delivery"
      if Spree::Config[:backorder_charge] || Spree::Config[:check_categories]
        @order.shipments.each do |shipment|
          if shipment.backordered? && Spree::Config[:backorder_charge]
            shipment.update_column(:cost, 0)
          end
          if @order.shipments.count > 1 && shipment.id != @order.shipments.first.id && Spree::Config[:check_categories]
              shipment.update_column(:cost, 0)
          end
        end
        @order.reload.update!
      end
    end

    def check_registration
      return unless Spree::Auth::Config[:registration_step]
      return if spree_current_user or current_order.email
      store_location
      redirect_to spree.signup_path
    end

     def before_address
        # if the user has a default address, a callback takes care of setting
        # that; but if he doesn't, we need to build an empty one here
        @order.bill_address = !spree_current_user.blank? ? spree_current_user.bill_address : Address.build_default
        @order.ship_address = ( !spree_current_user.blank? ? spree_current_user.ship_address : Address.build_default ) if @order.checkout_steps.include?('delivery')
    end
end

{'fraction_non_alphanumeric': 0.09334537789822343, 'fraction_numerical': 0.0030111412225233363, 'mean_word_length': 3.3653088042049935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3014686', 'n_tokens_mistral': 1002, 'n_tokens_neox': 970, 'n_words': 216}