Sha256: db0ce5e2101411320ac58f7700e3f21295257d7d8c6ca6901a9b3e2fc1b2a87c

Contents?: true

Size: 751 Bytes

Versions: 14

Compression:

Stored size: 751 Bytes

Contents

module ShopifyAPI
  class Product < Base
    include Events
    include Metafields

    # compute the price range
    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

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

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

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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
shopify_api-7.0.2 lib/shopify_api/resources/product.rb
shopify_api-7.0.1 lib/shopify_api/resources/product.rb
shopify_api-7.0.0 lib/shopify_api/resources/product.rb
shopify_api-6.0.0 lib/shopify_api/resources/product.rb
shopify_api-5.2.4 lib/shopify_api/resources/product.rb
shopify_api-5.2.3 lib/shopify_api/resources/product.rb
shopify_api-5.2.2 lib/shopify_api/resources/product.rb
shopify_api-5.2.1 lib/shopify_api/resources/product.rb
shopify_api-5.2.0 lib/shopify_api/resources/product.rb
shopify_api-5.1.0 lib/shopify_api/resources/product.rb
shopify_api-5.0.0 lib/shopify_api/resources/product.rb
shopify_api-4.13.0 lib/shopify_api/resources/product.rb
shopify_api-4.12.0 lib/shopify_api/resources/product.rb
shopify_api-4.11.0 lib/shopify_api/resources/product.rb