class ShopifyAPI::Product
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/shopify_api/resources/product.rb, line 9 def initialize(*) super self.attributes.except!('total_inventory') unless allow_inventory_params? end
Public Instance Methods
add_to_collection(collection)
click to toggle source
# File lib/shopify_api/resources/product.rb, line 38 def add_to_collection(collection) collection.add_product(self) end
collections()
click to toggle source
# File lib/shopify_api/resources/product.rb, line 30 def collections CustomCollection.find(:all, params: { product_id: self.id }) end
price_range()
click to toggle source
compute the price range
# 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)
click to toggle source
# File lib/shopify_api/resources/product.rb, line 42 def remove_from_collection(collection) collection.remove_product(self) end
smart_collections()
click to toggle source
# 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)
click to toggle source
Calls superclass method
# 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
Private Instance Methods
allow_inventory_params?()
click to toggle source
# File lib/shopify_api/resources/product.rb, line 55 def allow_inventory_params? Base.api_version < ApiVersion.find_version('2019-10') end
raise_deprecated_inventory_call(parameter)
click to toggle source
# File lib/shopify_api/resources/product.rb, line 48 def raise_deprecated_inventory_call(parameter) raise( ShopifyAPI::ValidationException, "'#{parameter}' is deprecated - see https://help.shopify.com/en/api/guides/inventory-migration-guide", ) end