Class: MageRecord::Product
- Inherits:
-
EavRecord
- Object
- ActiveRecord::Base
- EavRecord
- MageRecord::Product
show all
- Defined in:
- lib/magerecord/fitlion/product.rb,
lib/magerecord/product.rb
Overview
add custom FitLion-specific product methods
Instance Method Summary
collapse
Methods inherited from EavRecord
eav_attributes, eav_prefix, #method_missing, #respond_to?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class MageRecord::EavRecord
Instance Method Details
#attributes ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/magerecord/fitlion/product.rb', line 8
def attributes
if @attribs.nil?
@attribs = {}
if %w{simple virtual}.include?(type_id)
attribs = set.downcase.gsub(/.*\((.+)\)/, "\\1").gsub(/ only/, '').split(' + ') - ['brand']
attribs.map{ |a| a.split(' ').join('_') }.each do |attrib|
@attribs[attrib] = send(attrib)
end
end
end
@attribs
end
|
#enabled? ⇒ Boolean
26
27
28
29
30
|
# File 'lib/magerecord/product.rb', line 26
def enabled?
status.to_i == 1
end
|
#full_name(with_brand = true) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/magerecord/fitlion/product.rb', line 26
def full_name(with_brand = true)
if @fname.nil?
@fname = "#{name} (#{uom})"
@fname = "(#{brand}) #{@fname}" if with_brand and brand
@fname = "#{@fname}#{attributes.values.map{ |a| " (#{a})" }.join}"
end
@fname
end
|
#in_stock? ⇒ Boolean
21
22
23
|
# File 'lib/magerecord/product.rb', line 21
def in_stock?
stock.is_in_stock?
end
|
#is_supplement? ⇒ Boolean
40
41
42
|
# File 'lib/magerecord/fitlion/product.rb', line 40
def is_supplement?
set.downcase.include? 'supplement'
end
|
#qty ⇒ Object
16
17
18
|
# File 'lib/magerecord/product.rb', line 16
def qty
stock.qty.to_i
end
|
#set ⇒ Object
33
34
35
36
|
# File 'lib/magerecord/product.rb', line 33
def set
product_attribute_set.attribute_set_name
end
|
#uom ⇒ Object
4
5
6
|
# File 'lib/magerecord/fitlion/product.rb', line 4
def uom
"#{measurement} #{unit}"
end
|