Class: ShopifyAPI::Product

Inherits:
Base
  • Object
show all
Includes:
Events, Metafields
Defined in:
lib/shopify_api/resources/product.rb

Instance Method Summary collapse

Methods included from Metafields

#add_metafield, #metafields

Methods included from Events

#events

Methods inherited from Base

activate_session, api_version, api_version=, #as_json, clear_session, early_july_pagination?, #encode, headers, init_prefix, init_prefix_explicit, #persisted?, prefix, prefix=, prefix_source, resource_prefix, resource_prefix=, version_validation!

Methods included from Countable

#count

Instance Method Details

#add_to_collection(collection) ⇒ Object



36
37
38
# File 'lib/shopify_api/resources/product.rb', line 36

def add_to_collection(collection)
  collection.add_product(self)
end

#collectionsObject



28
29
30
# File 'lib/shopify_api/resources/product.rb', line 28

def collections
  CustomCollection.find(:all, :params => {:product_id => self.id})
end

#price_rangeObject

compute the price range



9
10
11
12
13
14
15
16
17
# File 'lib/shopify_api/resources/product.rb', line 9

def price_range
  prices = variants.collect(&:price).collect(&:to_f)
  format =  "%0.2f"
  if prices.min != prices.max
    "#{format % prices.min} - #{format % prices.max}"
  else
    format % prices.min
  end
end

#remove_from_collection(collection) ⇒ Object



40
41
42
# File 'lib/shopify_api/resources/product.rb', line 40

def remove_from_collection(collection)
  collection.remove_product(self)
end

#serializable_hash(options = {}) ⇒ Object



24
25
26
# File 'lib/shopify_api/resources/product.rb', line 24

def serializable_hash(options = {})
  allow_inventory_params? ? super(options) : super(options).except('total_inventory')
end

#smart_collectionsObject



32
33
34
# File 'lib/shopify_api/resources/product.rb', line 32

def smart_collections
  SmartCollection.find(:all, :params => {:product_id => self.id})
end

#total_inventory=(new_value) ⇒ Object



19
20
21
22
# File 'lib/shopify_api/resources/product.rb', line 19

def total_inventory=(new_value)
  raise_deprecated_inventory_call('total_inventory') unless allow_inventory_params?
  super
end