<commit_before># encoding : utf-8
class BasketsController < AdminController

  before_filter :load_basket, :only => [:show, :edit, :change , :update, :destroy , :order , :print, :purchase]

  def index
    @q = Basket.search( params[:q] , :include => {:items => :product} )
    @basket_scope = @q.result( :distinct => true )
    @basket_scope_for_scope = @basket_scope.dup
    unless params[:scope].blank?
      @basket_scope = @basket_scope.send(params[:scope])
    end
    @baskets = @basket_scope.paginate( :page => params[:page], :per_page => 20 ).to_a
  end

  def print
    order = @basket.kori || Order.new( :basket => @basket )
    order.paid_on    = Date.today unless order.paid_on
    order.shipped_on = Date.today unless order.shipped_on
    order.shipment_price = 0 unless order.shipment_price
    order.shipment_tax   = 0 unless order.shipment_tax
    order.email = current_clerk.email
    order.save!
    redirect_to :action => :print , :controller => :orders , :id => order.id
  end

  def show
  end

  #as an action this order is mean as a verb, ie order this basket
  def order
    redirect_to :action => :show    if @basket.items.empty?
    order = Order.create! :basket => @basket , :email => current_clerk.email , :orderd_on => Date.today
    redirect_to :action => :show , :controller => :orders , :id => order.id
  end

  def purchase
    redirect_to :action => :show    if @basket.items.empty?
    name = "purchase"
    #if inventory -> "inventory" etc
    purchase = Purchase.create! :basket => @basket
    redirect_to :action => :show , :controller => :purchases , :id => purchase.id
  end

  def new
    @basket = Basket.create!
    render "show"
  end

  def edit
    if pid = params[:add]
      item = @basket.items.find { |item| item.id.to_s == pid }
      item.quantity += 1
      item.save
#      flash.notice = t('product_added')
    end
    if pid = params[:delete]
      item = @basket.items.find { |item| item.id.to_s == pid }
      item.quantity -= 1
      if item.quantity == 0
        @basket.items.delete item
      else
        item.save
      end
#      flash.notice = t('item_removed')
    end
    if discount = params[:discount]
      if i_id = params[:item]
        item = @basket.items.find { |item| item.id.to_s == i_id }
        item_discount( item , discount )
      else
        @basket.items.each do |item|
          item_discount( item , discount )
        end
      end
    end
    if p_id = params[:product]
      prod = Product.find p_id
      #errors ?
      @basket.add_product prod
    end
    if ean = params[:ean]
      prod = Product.find_by_ean ean
      if(prod)
        @basket.add_product prod
      else
        # stor the basket in the session ( or the url ???)
        redirect_to :action => :index, :controller => :products, :q => {"name_or_product_name_cont"=> ean},:basket => @basket.id

        return
      end
    end
    redirect_to  :action => :show
  end

  def create
    @basket = Basket.create(params_for_basket)
    if @basket.save
      redirect_to basket_path(@basket), :flash => { :notice => t(:create_success, :model => "basket") }
    else
      render :action => "new"
    end
  end

  def update
    if @basket.update_attributes(params_for_basket)
      redirect_to basket_path(@basket), :flash => { :notice => t(:update_success, :model => "basket") }
    else
      render :action => "show"
    end
  end

  def destroy
    @basket.destroy
    redirect_to baskets_url
  end<commit_msg>flashes and scode search in case ean fails<commit_after># encoding : utf-8
class BasketsController < AdminController

  before_filter :load_basket, :only => [:show, :edit, :change , :update, :destroy , :order , :print, :purchase]

  def index
    @q = Basket.search( params[:q] , :include => {:items => :product} )
    @basket_scope = @q.result( :distinct => true )
    @basket_scope_for_scope = @basket_scope.dup
    unless params[:scope].blank?
      @basket_scope = @basket_scope.send(params[:scope])
    end
    @baskets = @basket_scope.paginate( :page => params[:page], :per_page => 20 ).to_a
  end

  def print
    order = @basket.kori || Order.new( :basket => @basket )
    order.paid_on    = Date.today unless order.paid_on
    order.shipped_on = Date.today unless order.shipped_on
    order.shipment_price = 0 unless order.shipment_price
    order.shipment_tax   = 0 unless order.shipment_tax
    order.email = current_clerk.email
    order.save!
    redirect_to :action => :print , :controller => :orders , :id => order.id
  end

  def show
  end

  #as an action this order is mean as a verb, ie order this basket
  def order
    redirect_to :action => :show    if @basket.items.empty?
    order = Order.create! :basket => @basket , :email => current_clerk.email , :orderd_on => Date.today
    redirect_to :action => :show , :controller => :orders , :id => order.id
  end

  def purchase
    redirect_to :action => :show    if @basket.items.empty?
    name = "purchase"
    #if inventory -> "inventory" etc
    purchase = Purchase.create! :basket => @basket
    redirect_to :action => :show , :controller => :purchases , :id => purchase.id
  end

  def new
    @basket = Basket.create!
    render "show"
  end

  def edit
    if pid = params[:add]
      item = @basket.items.find { |item| item.id.to_s == pid }
      item.quantity += 1
      item.save
      flash.notice = t('product_added')
    end
    if pid = params[:delete]
      item = @basket.items.find { |item| item.id.to_s == pid }
      item.quantity -= 1
      if item.quantity == 0
        @basket.items.delete item
      else
        item.save
      end
      flash.notice = t('item_removed')
    end
    if discount = params[:discount]
      if i_id = params[:item]
        item = @basket.items.find { |item| item.id.to_s == i_id }
        item_discount( item , discount )
      else
        @basket.items.each do |item|
          item_discount( item , discount )
        end
      end
    end
    if p_id = params[:product]
      prod = Product.find p_id
      #errors ?
      @basket.add_product prod
      flash.notice = t('product_added')
    end
    if ean = params[:ean]
      prod = Product.find_by_ean ean
      if(prod)
        @basket.add_product prod
      else
        prod = Product.find_by_scode ean
        if(prod)
          @basket.add_product prod
        else
          # stor the basket in the session ( or the url ???)
          redirect_to :action => :index, :controller => :products, 
                :q => {"name_or_product_name_cont"=> ean},:basket => @basket.id
          return
        end
      end
    end
    redirect_to  :action => :show
  end

  def create
    @basket = Basket.create(params_for_basket)
    if @basket.save
      redirect_to basket_path(@basket), :flash => { :notice => t(:create_success, :model => "basket") }
    else
      render :action => "new"
    end
  end

  def update
    if @basket.update_attributes(params_for_basket)
      redirect_to basket_path(@basket), :flash => { :notice => t(:update_success, :model => "basket") }
    else
      render :action => "show"
    end
  end

  def destroy
    @basket.destroy
    redirect_to baskets_url
  end
{'fraction_non_alphanumeric': 0.12187281621243885, 'fraction_numerical': 0.002236198462613557, 'mean_word_length': 2.565520677628301, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, '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': '1350355', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2360, 'n_words': 612}