Class: VersacommerceAPI::Product
Class Method Summary
collapse
Instance Method Summary
collapse
#add_metafield, #metafields
#associated_resource
Methods inherited from Base
activate_session, all, clear_session, headers, root!
Methods included from Countable
#count
build, delete, headers
Constructor Details
#initialize(attributes, persisted = false) ⇒ Product
Returns a new instance of Product.
8
9
10
11
12
13
14
15
16
|
# File 'lib/versacommerce_api/resources/product.rb', line 8
def initialize(attributes, persisted = false)
super
if respond_to?(:shipping_types) && self.shipping_types.present?
self.shipping_types.map! do |shipping_type|
Carrier.new(shipping_type.attributes)
end
end
end
|
Class Method Details
.categories ⇒ Object
82
83
84
|
# File 'lib/versacommerce_api/resources/product.rb', line 82
def self.categories
get(:categories)
end
|
Instance Method Details
#amount_available(amount) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/versacommerce_api/resources/product.rb', line 33
def amount_available(amount)
if considers_stock
stock >= amount
else
true
end
end
|
#available ⇒ Object
29
30
31
|
# File 'lib/versacommerce_api/resources/product.rb', line 29
def available
amount_available(0) && active
end
|
#carriers ⇒ Object
57
58
59
|
# File 'lib/versacommerce_api/resources/product.rb', line 57
def carriers
associated_resource "carrier"
end
|
#featured_image ⇒ Object
66
67
68
|
# File 'lib/versacommerce_api/resources/product.rb', line 66
def featured_image
ProductImage.new(:src => featured_image_url)
end
|
#is_variant ⇒ Object
41
42
43
|
# File 'lib/versacommerce_api/resources/product.rb', line 41
def is_variant
!product_id.nil?
end
|
#price_range ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/versacommerce_api/resources/product.rb', line 19
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
49
50
51
|
# File 'lib/versacommerce_api/resources/product.rb', line 49
def product_images
associated_resource "product_image"
end
|
#properties ⇒ Object
45
46
47
|
# File 'lib/versacommerce_api/resources/product.rb', line 45
def properties
associated_resource "property"
end
|
61
62
63
64
|
# File 'lib/versacommerce_api/resources/product.rb', line 61
def tags
return [] if self.respond_to?("tag_list") && self.send("tag_list").blank?
tag_list.split(",").map(&:strip)
end
|
#tax_for_country(country = nil) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/versacommerce_api/resources/product.rb', line 70
def tax_for_country country = nil
begin
if country.present?
get(:tax_for_country, country: country)
else
get(:tax_for_country)
end
rescue ActiveResource::ResourceNotFound
return nil
end
end
|
#variants ⇒ Object
53
54
55
|
# File 'lib/versacommerce_api/resources/product.rb', line 53
def variants
associated_resource "variant"
end
|