Class: BigcommerceAPI::Sku

Inherits:
Resource show all
Defined in:
lib/bigcommerce_api/sku.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#errors

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

belongs_to, #create, has_many, has_one, #initialize, #resource, resource, #save

Methods inherited from Base

#attributes, clean!, date_adjust, #initialize, #store, #time, to_rfc2822

Constructor Details

This class inherits a constructor from BigcommerceAPI::Resource

Instance Attribute Details

#bin_picking_numberObject

Returns the value of attribute bin_picking_number.



4
5
6
# File 'lib/bigcommerce_api/sku.rb', line 4

def bin_picking_number
  @bin_picking_number
end

#cost_priceObject

Returns the value of attribute cost_price.



4
5
6
# File 'lib/bigcommerce_api/sku.rb', line 4

def cost_price
  @cost_price
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/bigcommerce_api/sku.rb', line 4

def id
  @id
end

#inventory_levelObject

Returns the value of attribute inventory_level.



4
5
6
# File 'lib/bigcommerce_api/sku.rb', line 4

def inventory_level
  @inventory_level
end

#inventory_warning_levelObject

Returns the value of attribute inventory_warning_level.



4
5
6
# File 'lib/bigcommerce_api/sku.rb', line 4

def inventory_warning_level
  @inventory_warning_level
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/bigcommerce_api/sku.rb', line 4

def options
  @options
end

#product_idObject

Returns the value of attribute product_id.



4
5
6
# File 'lib/bigcommerce_api/sku.rb', line 4

def product_id
  @product_id
end

#skuObject

Returns the value of attribute sku.



4
5
6
# File 'lib/bigcommerce_api/sku.rb', line 4

def sku
  @sku
end

#upcObject

Returns the value of attribute upc.



4
5
6
# File 'lib/bigcommerce_api/sku.rb', line 4

def upc
  @upc
end

Class Method Details

.all(product_id, params = {}) ⇒ Object



45
46
47
48
# File 'lib/bigcommerce_api/sku.rb', line 45

def all(product_id, params={})
  resources = BigcommerceAPI::Base.get("/products/#{product_id}/skus", :query => date_adjust(params))
  (resources.success? and !resources.nil?) ? resources.collect{|r| self.new(r)} : []
end

.find(product_id, id) ⇒ Object



50
51
52
53
# File 'lib/bigcommerce_api/sku.rb', line 50

def find(product_id, id)
  r = BigcommerceAPI::Base.get("/products/#{product_id}/skus/#{id}")
  (r.success? and !r.nil?) ? self.new(r) : nil
end

Instance Method Details

#descriptionObject



35
36
37
38
39
40
41
42
# File 'lib/bigcommerce_api/sku.rb', line 35

def description
  out = Array.new
  po = self.product_option
  ov = self.option_value
  out << po.display_name if po
  out << ov.label if ov
  return out.join(' ')
end

#option_valueObject



29
30
31
32
33
# File 'lib/bigcommerce_api/sku.rb', line 29

def option_value
  option_id = self.product_option.option_id
  ov = BigcommerceAPI::Base.get '/options/' + option_id.to_s + '/values/' + self.option_value_id.to_s
  (ov.success? and !ov.nil?) ? OptionValue.new(ov) : nil
end

#option_value_idObject



20
21
22
# File 'lib/bigcommerce_api/sku.rb', line 20

def option_value_id
  self.options.first['option_value_id']
end

#parentObject



12
13
14
# File 'lib/bigcommerce_api/sku.rb', line 12

def parent
  'product'
end

#product_optionObject



24
25
26
27
# File 'lib/bigcommerce_api/sku.rb', line 24

def product_option
  po = BigcommerceAPI::Base.get '/products/' + self.product_id.to_s + '/options/' + self.product_option_id.to_s
  (po.success? and !po.nil?) ? ProductOption.new(po) : nil
end

#product_option_idObject



16
17
18
# File 'lib/bigcommerce_api/sku.rb', line 16

def product_option_id
  self.options.first['product_option_id']
end

#resource_urlObject



8
9
10
# File 'lib/bigcommerce_api/sku.rb', line 8

def resource_url
  "products/#{self.product_id}/skus"
end