Sha256: 334c88511257d930ec26495e7e4de714bb35b783fc6d672d19536bf0e9d07a3e

Contents?: true

Size: 1.66 KB

Versions: 13

Compression:

Stored size: 1.66 KB

Contents

class Product < ActiveRecord::Base
  # Scopes and Inclusions
  include Forge::Reorderable
  default_scope :order => 'products.list_order ASC'
  scope :published, :conditions => ["published = ?", true]

  # Relationships
  has_many :images, :class_name => "ProductImage"
  accepts_nested_attributes_for :images, :reject_if => lambda {|i| i[:image_asset_id].blank? && i[:id].blank? }, :allow_destroy => true
  has_and_belongs_to_many :tax_rates
  belongs_to :product_category
  belongs_to :sale
  #serialize :options # { :colours => {:Red => {:stock => 123, :selected => true} , :Blue => {:stock => 0}}, :sizes => {:small => {:stock => 10}} }

  # Validations
  validates_presence_of :title, :product_category
  validates_presence_of :short_description, :description, :if => :published
  validates_numericality_of :price, :flat_rate_shipping, :weight, :width, :height, :depth, :greater_than_or_equal_to => 0.00


  # for when the product is used in the cart or in an order hash
  def quantity
    @quantity ||= 1
  end

  def quantity=(quantity)
    @quantity = quantity
  end

  def to_param
    "#{id}-#{title.gsub(/[^a-z0-9]+/i, '-')}".downcase
  end

  def options_yaml
    self.options
  end

  def options_hash
    YAML::load(self.options)
  end

  def all_breadcrumbs(join_character = ' > ')
    @all_breadcrumbs = []
    self.product_categories.each do |category|
      @breadcrumb = category.breadcrumb
      @all_breadcrumbs << @breadcrumb
    end

    if @all_breadcrumbs.blank?
      @all_breadcrumbs = "No categories."
    else
      @all_breadcrumbs.join(', ')
    end
  end

  def self.find_with_images(id)
    includes(:images).order('product_images.list_order').find(id)
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
forge-cli-0.0.18 lib/forge/app/models/product.rb
forge-cli-0.0.17 lib/forge/app/models/product.rb
forge-cli-0.0.16 lib/forge/app/models/product.rb
forge-cli-0.0.15 lib/forge/app/models/product.rb
forge-cli-0.0.14 lib/forge/app/models/product.rb
forge-cli-0.0.13 lib/forge/app/models/product.rb
forge-cli-0.0.12 lib/forge/app/models/product.rb
forge-cli-0.0.11 lib/forge/app/models/product.rb
forge-cli-0.0.10 lib/forge/app/models/product.rb
forge-cli-0.0.9 lib/forge/app/models/product.rb
forge-cli-0.0.8 lib/forge/app/models/product.rb
forge-cli-0.0.7 lib/forge/app/models/product.rb
forge-cli-0.0.6 lib/forge/app/models/product.rb