Class: VersacommerceAPI::Product
Instance Method Summary
collapse
#associated_resource
Methods inherited from Base
activate_session, all, clear_session, headers, root!
Methods included from Countable
#count
build, delete, headers
Instance Method Details
#amount_available(amount) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/versacommerce_api/resources/product.rb', line 21
def amount_available(amount)
if considers_stock
stock >= amount
else
true
end
end
|
#available ⇒ Object
17
18
19
|
# File 'lib/versacommerce_api/resources/product.rb', line 17
def available
amount_available(0) && active
end
|
#featured_image ⇒ Object
50
51
52
|
# File 'lib/versacommerce_api/resources/product.rb', line 50
def featured_image
ProductImage.new(:src => featured_image_url)
end
|
#is_variant ⇒ Object
29
30
31
|
# File 'lib/versacommerce_api/resources/product.rb', line 29
def is_variant
!product_id.nil?
end
|
#price_range ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/versacommerce_api/resources/product.rb', line 7
def price_range
prices = variants.collect(&:price)
format = "%0.2f"
if prices.min != prices.max
"#{format % prices.min} - #{format % prices.max}"
else
format % prices.min
end
end
|
#product_images ⇒ Object
37
38
39
|
# File 'lib/versacommerce_api/resources/product.rb', line 37
def product_images
associated_resource "product_image"
end
|
#properties ⇒ Object
33
34
35
|
# File 'lib/versacommerce_api/resources/product.rb', line 33
def properties
associated_resource "property"
end
|
45
46
47
48
|
# File 'lib/versacommerce_api/resources/product.rb', line 45
def tags
return [] if self.respond_to?("tag_list") && self.send("tag_list").blank?
tag_list.split(",").map(&:strip)
end
|
#variants ⇒ Object
41
42
43
|
# File 'lib/versacommerce_api/resources/product.rb', line 41
def variants
associated_resource "variant"
end
|