class MageRecord::Product

add custom FitLion-specific product methods

Public Instance Methods

attributes() click to toggle source
# File lib/magerecord/fitlion/product.rb, line 8
def attributes
  if @attribs.nil?
    @attribs = {}

    # only simple/virtual products will have custom attributes
    if %w{simple virtual}.include?(type_id)
      # get all custom product attributes specific to attribute set (except "brand")
      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?() click to toggle source
# File lib/magerecord/product.rb, line 26
def enabled?
  # note: a magento product's enabled/disabled status is stored in EAV attribute code "status"
  # 1 = enabled, 2 = disabled
  status.to_i == 1
end
full_name(with_brand = true) click to toggle source
# File lib/magerecord/fitlion/product.rb, line 26
def full_name(with_brand = true)
  if @fname.nil?
    @fname = "#{name} (#{uom})"

    # note: most bundles are not associated with any brand
    @fname = "(#{brand}) #{@fname}" if with_brand and brand

    @fname = "#{@fname}#{attributes.values.map{ |a| " (#{a})" }.join}"
  end

  # return cached full name
  @fname
end
in_stock?() click to toggle source
# File lib/magerecord/product.rb, line 21
def in_stock?
  stock.is_in_stock?
end
is_supplement?() click to toggle source
# File lib/magerecord/fitlion/product.rb, line 40
def is_supplement?
  set.downcase.include? 'supplement'
end
qty() click to toggle source
# File lib/magerecord/product.rb, line 16
def qty
  stock.qty.to_i
end
set() click to toggle source
# File lib/magerecord/product.rb, line 33
def set
  # return product's attribute set
  product_attribute_set.attribute_set_name
end
uom() click to toggle source
# File lib/magerecord/fitlion/product.rb, line 4
def uom
  "#{measurement} #{unit}"
end