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
22
23
24
25
26
27
28
|
# File 'lib/versacommerce_api/resources/product.rb', line 22
def amount_available(amount)
if considers_stock
stock >= amount
else
true
end
end
|
#available ⇒ Object
18
19
20
|
# File 'lib/versacommerce_api/resources/product.rb', line 18
def available
amount_available(0) && active
end
|
#featured_image ⇒ Object
51
52
53
|
# File 'lib/versacommerce_api/resources/product.rb', line 51
def featured_image
ProductImage.new(:src => featured_image_url)
end
|
#is_variant ⇒ Object
30
31
32
|
# File 'lib/versacommerce_api/resources/product.rb', line 30
def is_variant
!product_id.nil?
end
|
#price_range ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/versacommerce_api/resources/product.rb', line 8
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
38
39
40
|
# File 'lib/versacommerce_api/resources/product.rb', line 38
def product_images
associated_resource "product_image"
end
|
#properties ⇒ Object
34
35
36
|
# File 'lib/versacommerce_api/resources/product.rb', line 34
def properties
associated_resource "property"
end
|
46
47
48
49
|
# File 'lib/versacommerce_api/resources/product.rb', line 46
def tags
return [] if self.respond_to?("tag_list") && self.send("tag_list").blank?
tag_list.split(",").map(&:strip)
end
|
#variants ⇒ Object
42
43
44
|
# File 'lib/versacommerce_api/resources/product.rb', line 42
def variants
associated_resource "variant"
end
|