Class: Product

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Forge::Reorderable
Defined in:
lib/forge/app/models/product.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Forge::Reorderable

included

Class Method Details

.find_with_images(id) ⇒ Object



56
57
58
# File 'lib/forge/app/models/product.rb', line 56

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

Instance Method Details

#all_breadcrumbs(join_character = ' > ') ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/forge/app/models/product.rb', line 42

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

#options_hashObject



38
39
40
# File 'lib/forge/app/models/product.rb', line 38

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

#options_yamlObject



34
35
36
# File 'lib/forge/app/models/product.rb', line 34

def options_yaml
  self.options
end

#quantityObject

for when the product is used in the cart or in an order hash



22
23
24
# File 'lib/forge/app/models/product.rb', line 22

def quantity
  @quantity ||= 1
end

#quantity=(quantity) ⇒ Object



26
27
28
# File 'lib/forge/app/models/product.rb', line 26

def quantity=(quantity)
  @quantity = quantity
end

#to_paramObject



30
31
32
# File 'lib/forge/app/models/product.rb', line 30

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