class VersacommerceAPI::Product

Public Class Methods

categories() click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 81
def self.categories
  get(:categories)
end
new(attributes, persisted = false) click to toggle source
Calls superclass method
# File lib/versacommerce_api/resources/product.rb, line 7
def initialize(attributes, persisted = false)
  super

  if respond_to?(:shipping_types) && self.shipping_types.present?
    self.shipping_types.map! do |shipping_type|
      Carrier.new(shipping_type.attributes)
    end
  end
end

Public Instance Methods

amount_available(amount) click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 32
def amount_available(amount)
  if considers_stock
    stock >= amount
  else
    true
  end
end
available() click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 28
def available
  amount_available(0) && active
end
carriers() click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 56
def carriers
  associated_resource "carrier"
end
is_variant() click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 40
def is_variant
  !product_id.nil?
end
price_range() click to toggle source

compute the price range

# File lib/versacommerce_api/resources/product.rb, line 18
def price_range
  prices = variants.collect(&:price)
  format =  "%0.2f"
  if prices.min != prices.max
    "#{format % prices.min} - #{format % prices.max}"
  else
    format % prices.min
  end
end
product_images() click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 48
def product_images
  associated_resource "product_image"
end
properties() click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 44
def properties
   associated_resource "property"
end
tags() click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 60
def tags
  return [] if self.respond_to?("tag_list") && self.send("tag_list").blank?
  tag_list.split(",").map(&:strip)
end
tax_for_country(country = nil) click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 69
def tax_for_country country = nil
  begin
    if country.present?
      get(:tax_for_country, country: country)
    else
      get(:tax_for_country) # Retrieve tax for default shipping country
    end
  rescue ActiveResource::ResourceNotFound
    return nil
  end
end
variants() click to toggle source
# File lib/versacommerce_api/resources/product.rb, line 52
def variants
  associated_resource "variant"
end