<commit_before>class ProductDetail < ActiveRecord::Base
  belongs_to :product

  #has_one :order_item
  validates_uniqueness_of :inventory_key, allow_nil: true, message: "Inventory Key must be Unique!!"

  def self.find_or_create(attributes)
    ProductDetail.where(attributes).first || ProductDetail.create(attributes)
  end
  
  def self.key_field
    return "inventory_key"
  end
  
  def swatch
    if (!!Settings.force_system_swatches)
      SystemImages.all.where(title: self.color).first.image_url.to_s
    else
      begin 
        self.product.pictures.where(title: self.color).first.image_url(:swatch).to_s 
      rescue 
        begin
          SystemImages.all.where(title: self.color).first.image_url.to_s
        rescue 
           ActionController::Base.helpers.asset_path("blank.png")
#        "blank.png"
        end
      end
    end

  end
  
  def thumb
    #self.product.pictures.where(:title=>self.color, :active_flag=>true).first.image_url(:thumb).to_s rescue "/images/site/blank.png"

    begin 
      self.product.pictures.where(title: self.color).first.image_url(:thumb).to_s 
    rescue 
      #begin
      #  self.product.pictures.first.image_url(:thumb).to_s
      #rescue 
      begin
        SystemImages.all.where(title: self.color).first.image_url(:thumb).to_s
      rescue 
                ActionController::Base.helpers.asset_path("blank.png")

      #  "/images/site/blank.png"
      end
      # end
    end

  end

  def colorpattern
    
  end
  
  def medium
    self.product.pictures.where(title: self.color).first.image_url(:medium).to_s rescue "/images/site/blank.png"

  end
  
  def small
    #  self.product.pictures.where(:title=>self.color).first.image_url(:small).to_s rescue "/images/site/blank.png"
    begin 
      self.product.pictures.where(title: self.color).first.image_url(:small).to_s 
    rescue 
      begin
        SystemImages.all.where(title: self.color).first.image_url(:small).to_s
      rescue 
        ActionController::Base.helpers.asset_path("blank.png")<commit_msg>added using small image if no color is defined for a product.  The small is used in the shopping cart.<commit_after>class ProductDetail < ActiveRecord::Base
  belongs_to :product

  #has_one :order_item
  validates_uniqueness_of :inventory_key, allow_nil: true, message: "Inventory Key must be Unique!!"

  def self.find_or_create(attributes)
    ProductDetail.where(attributes).first || ProductDetail.create(attributes)
  end
  
  def self.key_field
    return "inventory_key"
  end
  
  def swatch
    if (!!Settings.force_system_swatches)
      SystemImages.all.where(title: self.color).first.image_url.to_s
    else
      begin 
        self.product.pictures.where(title: self.color).first.image_url(:swatch).to_s 
      rescue 
        begin
          SystemImages.all.where(title: self.color).first.image_url.to_s
        rescue 
           ActionController::Base.helpers.asset_path("blank.png")
#        "blank.png"
        end
      end
    end

  end
  
  def thumb
    #self.product.pictures.where(:title=>self.color, :active_flag=>true).first.image_url(:thumb).to_s rescue "/images/site/blank.png"

    begin 
      self.product.pictures.where(title: self.color).first.image_url(:thumb).to_s 
    rescue 
      #begin
      #  self.product.pictures.first.image_url(:thumb).to_s
      #rescue 
      begin
        SystemImages.all.where(title: self.color).first.image_url(:thumb).to_s
      rescue 
                ActionController::Base.helpers.asset_path("blank.png")

      #  "/images/site/blank.png"
      end
      # end
    end

  end

  def colorpattern
    
  end
  
  def medium
    self.product.pictures.where(title: self.color).first.image_url(:medium).to_s rescue "/images/site/blank.png"

  end
  
  def small
    #  self.product.pictures.where(:title=>self.color).first.image_url(:small).to_s rescue "/images/site/blank.png"
    begin 
      self.product.pictures.where(title: self.color).first.image_url(:small).to_s 
    rescue 
      begin
        SystemImages.all.where(title: self.color).first.image_url(:small).to_s
      rescue 
        self.product.pictures.first.image_url(:small).to_s
        # ActionController::Base.helpers.asset_path("blank.png")
{'fraction_non_alphanumeric': 0.11450924608819346, 'fraction_numerical': 0.0, 'mean_word_length': 2.856489945155393, 'pattern_counts': {'":': 0, '<': 5, '<?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': '332314', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1362, 'n_words': 209}