Class: ShopifyAPI::Product
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
Returns a new instance of Product.
9
10
11
12
|
# File 'lib/shopify_api/resources/product.rb', line 9
def initialize(*)
super
self.attributes.except!('total_inventory') unless allow_inventory_params?
end
|
Instance Method Details
#add_to_collection(collection) ⇒ Object
38
39
40
|
# File 'lib/shopify_api/resources/product.rb', line 38
def add_to_collection(collection)
collection.add_product(self)
end
|
#collections ⇒ Object
30
31
32
|
# File 'lib/shopify_api/resources/product.rb', line 30
def collections
CustomCollection.find(:all, params: { product_id: self.id })
end
|
#price_range ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/shopify_api/resources/product.rb', line 15
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
42
43
44
|
# File 'lib/shopify_api/resources/product.rb', line 42
def remove_from_collection(collection)
collection.remove_product(self)
end
|
#smart_collections ⇒ Object
34
35
36
|
# File 'lib/shopify_api/resources/product.rb', line 34
def smart_collections
SmartCollection.find(:all, params: { product_id: self.id })
end
|
#total_inventory=(new_value) ⇒ Object
25
26
27
28
|
# File 'lib/shopify_api/resources/product.rb', line 25
def total_inventory=(new_value)
raise_deprecated_inventory_call('total_inventory') unless allow_inventory_params?
super
end
|