Class: ShopifyAPI::Product

Inherits:
Base 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, #as_json, clear_session, #encode, #headers, init_prefix, init_prefix_explicit, #persisted?

Methods included from Countable

#count

Methods inherited from ActiveResource::Base

delete, headers

Instance Method Details

#add_to_collection(collection) ⇒ Object



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

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

#collectionsObject



17
18
19
# File 'lib/shopify_api/resources/product.rb', line 17

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

#price_rangeObject

compute the price range



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

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



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

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

#smart_collectionsObject



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

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