product.rb 767 B

123456789101112131415161718192021222324252627282930313233
  1. module ShopifyAPI
  2. class Product < Base
  3. include Events
  4. include Metafields
  5. # compute the price range
  6. def price_range
  7. prices = variants.collect(&:price).collect(&:to_f)
  8. format = "%0.2f"
  9. if prices.min != prices.max
  10. "#{format % prices.min} - #{format % prices.max}"
  11. else
  12. format % prices.min
  13. end
  14. end
  15. def collections
  16. CustomCollection.find(:all, :params => {:product_id => self.id})
  17. end
  18. def smart_collections
  19. SmartCollection.find(:all, :params => {:product_id => self.id})
  20. end
  21. def add_to_collection(collection)
  22. collection.add_product(self)
  23. end
  24. def remove_from_collection(collection)
  25. collection.remove_product(self)
  26. end
  27. end
  28. end