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

#assign_attributes, belongs_to, #changed, #create, #delete, has_many, has_one, http_request, #initialize, #mark_dirty!, #reload, #resource, resource, #save, #update_attributes

Methods inherited from Base

#attributes, clean!, date_adjust, default_options, #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.



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

def bin_picking_number
  @bin_picking_number
end

#cost_priceObject

Returns the value of attribute cost_price.



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

def cost_price
  @cost_price
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#inventory_levelObject

Returns the value of attribute inventory_level.



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

def inventory_level
  @inventory_level
end

#inventory_warning_levelObject

Returns the value of attribute inventory_warning_level.



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

def inventory_warning_level
  @inventory_warning_level
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#product_idObject

Returns the value of attribute product_id.



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

def product_id
  @product_id
end

#skuObject

Returns the value of attribute sku.



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

def sku
  @sku
end

#upcObject

Returns the value of attribute upc.



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

def upc
  @upc
end

Class Method Details

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



62
63
64
65
# File 'lib/bigcommerce_api/sku.rb', line 62

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



67
68
69
70
# File 'lib/bigcommerce_api/sku.rb', line 67

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



47
48
49
50
51
52
53
54
# File 'lib/bigcommerce_api/sku.rb', line 47

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

#find_for_reloadObject

we override this on resources that need paired IDs for find



57
58
59
# File 'lib/bigcommerce_api/sku.rb', line 57

def find_for_reload
  self.class.find(self.product_id, self.id)
end

#option_valueObject



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

def option_value
  po = self.product_option
  if po # we've got to have a product option for this to work
    option_id = po.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
  else
    return nil
  end
end

#option_value_idObject



27
28
29
# File 'lib/bigcommerce_api/sku.rb', line 27

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

#parentObject



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

def parent
  'product'
end

#product_optionObject



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

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



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

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

#resource_urlObject



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

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