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



58
59
60
# File 'lib/forge/app/models/product.rb', line 58

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

Instance Method Details

#all_breadcrumbs(join_character = ' > ') ⇒ Object



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

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



40
41
42
# File 'lib/forge/app/models/product.rb', line 40

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

#options_yamlObject



36
37
38
# File 'lib/forge/app/models/product.rb', line 36

def options_yaml
  self.options
end

#quantityObject

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



24
25
26
# File 'lib/forge/app/models/product.rb', line 24

def quantity
  @quantity ||= 1
end

#quantity=(quantity) ⇒ Object



28
29
30
# File 'lib/forge/app/models/product.rb', line 28

def quantity=(quantity)
  @quantity = quantity
end

#to_paramObject



32
33
34
# File 'lib/forge/app/models/product.rb', line 32

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