Sha256: a12ee819a493420d22d752264a20b898c48018d2ad1b5e3eba9619b3067aadd4

Contents?: true

Size: 826 Bytes

Versions: 13

Compression:

Stored size: 826 Bytes

Contents

class ProductCategory < ActiveRecord::Base
  include Forge::Reorderable
  default_scope :order => 'product_categories.list_order'
  before_destroy :validate_destroy
  has_many :products
  belongs_to :sale
  belongs_to :parent, :class_name => "ProductCategory", :foreign_key => "parent_id"
  has_many :subcategories, :class_name => "ProductCategory", :foreign_key => "parent_id", :dependent => :destroy, :order => "list_order"

  validates_presence_of :title

  def validate_destroy
    products.count < 1
  end

  def parents( category=self )
    #Probably need to modify this to use slug instead of title?  At least parameterize things.
    if category.parent.nil?
      return [category.title]
    else
      return parents(category.parent).concat([category.title])
    end
  end

  def path
    parents.join('/')
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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