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

Constructor Details

#initializeProduct

Returns a new instance of Product.


8
9
10
11
# File 'lib/shopify_api/resources/product.rb', line 8

def initialize(*)
  super
  self.attributes.except!('total_inventory') unless allow_inventory_params?
end

Instance Method Details

#add_to_collection(collection) ⇒ Object


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

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

#collectionsObject


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

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

#price_rangeObject

compute the price range


14
15
16
17
18
19
20
21
22
# File 'lib/shopify_api/resources/product.rb', line 14

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


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

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

#smart_collectionsObject


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

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

#total_inventory=(new_value) ⇒ Object


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

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