Class: Spree::Amazon::Product

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/amazon/product.rb

Direct Known Subclasses

Variant

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base

#attributes=, #initialize

Constructor Details

This class inherits a constructor from Spree::Amazon::Base

Instance Attribute Details

- (Object) binds

Returns the value of attribute binds



8
9
10
# File 'app/models/spree/amazon/product.rb', line 8

def binds
  @binds
end

- (Object) created_at

Returns the value of attribute created_at



8
9
10
# File 'app/models/spree/amazon/product.rb', line 8

def created_at
  @created_at
end

- (Object) description

Returns the value of attribute description



7
8
9
# File 'app/models/spree/amazon/product.rb', line 7

def description
  @description
end

- (Object) id

Returns the value of attribute id



7
8
9
# File 'app/models/spree/amazon/product.rb', line 7

def id
  @id
end

- (Object) images

Product images



89
90
91
# File 'app/models/spree/amazon/product.rb', line 89

def images
  @images.blank? ? [] : @images.map{ |x| Spree::Amazon::Image.new(x, @name) }
end

- (Object) name

Returns the value of attribute name



7
8
9
# File 'app/models/spree/amazon/product.rb', line 7

def name
  @name
end

- (Object) price

Returns the value of attribute price



7
8
9
# File 'app/models/spree/amazon/product.rb', line 7

def price
  @price
end

- (Object) props

Returns the value of attribute props



8
9
10
# File 'app/models/spree/amazon/product.rb', line 8

def props
  @props
end

- (Object) props_str

Returns the value of attribute props_str



8
9
10
# File 'app/models/spree/amazon/product.rb', line 8

def props_str
  @props_str
end

- (Object) sale_props

Returns the value of attribute sale_props



8
9
10
# File 'app/models/spree/amazon/product.rb', line 8

def sale_props
  @sale_props
end

- (Object) taxon_id

Returns the value of attribute taxon_id



7
8
9
# File 'app/models/spree/amazon/product.rb', line 7

def taxon_id
  @taxon_id
end

- (Object) taxon_name

Returns the value of attribute taxon_name



8
9
10
# File 'app/models/spree/amazon/product.rb', line 8

def taxon_name
  @taxon_name
end

- (Object) taxons

Returns the value of attribute taxons



7
8
9
# File 'app/models/spree/amazon/product.rb', line 7

def taxons
  @taxons.map{ |x| Spree::Amazon::Taxon.find(x[:id]) }
end

- (Object) updated_at

Returns the value of attribute updated_at



8
9
10
# File 'app/models/spree/amazon/product.rb', line 8

def updated_at
  @updated_at
end

- (Object) url

Returns the value of attribute url



7
8
9
# File 'app/models/spree/amazon/product.rb', line 7

def url
  @url
end

- (Object) variant_attributes

Returns the value of attribute variant_attributes



9
10
11
# File 'app/models/spree/amazon/product.rb', line 9

def variant_attributes
  @variant_attributes
end

- (Object) variant_options

Returns the value of attribute variant_options



9
10
11
# File 'app/models/spree/amazon/product.rb', line 9

def variant_options
  @variant_options
end

- (Object) variants

Variants



95
96
97
98
# File 'app/models/spree/amazon/product.rb', line 95

def variants
  @_variants ||= Spree::Amazon::Variant.build_variants_collection(self, @variants)
  @_variants
end

Class Method Details

+ (Object) class_name



15
16
17
# File 'app/models/spree/amazon/product.rb', line 15

def class_name
  "Spree::Amazon::Product"
end

+ (Object) find(product_asin)

Find product by ASIN



34
35
36
# File 'app/models/spree/amazon/product.rb', line 34

def find(product_asin)
  new( SpreeEcs::Product.find(product_asin, { :response_group => "Large, Variations" }))
end

+ (Object) multi_find(asins)



38
39
40
# File 'app/models/spree/amazon/product.rb', line 38

def multi_find(asins)
  SpreeEcs::Product.multi_find(asins, { :response_group => "Large, Variations" }).map{|v| new(v) }
end

+ (Object) name



19
20
21
# File 'app/models/spree/amazon/product.rb', line 19

def name
  "Product"
end

+ (Object) prepare_id(product_id)



23
24
25
# File 'app/models/spree/amazon/product.rb', line 23

def prepare_id(product_id)
  product_id.to_s
end

+ (Object) root_page(options)

Product for home page



28
29
30
# File 'app/models/spree/amazon/product.rb', line 28

def root_page(options)
  self.search(({:q => " *", :search_index => "All"}).merge(options) )
end

+ (Object) save_to_spree_or_find(amazon_id_or_id)



57
58
59
60
61
62
# File 'app/models/spree/amazon/product.rb', line 57

def save_to_spree_or_find(amazon_id_or_id)
  unless @product = ::Product.find_by_amazon_id(amazon_id_or_id)
    @product = find(amazon_id_or_id).try(:save_to_spree)
  end
  @product
end

+ (Object) search(options = { })

Search products



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/spree/amazon/product.rb', line 44

def search(options={ })
  @results = SpreeEcs::Product.search(options)
  unless @results.blank?
    Spree::Amazon::ProductCollection.build({ :products => @results[:products].map { |item| new(item) },
                                             :total_entries => @results[:total_entries],
                                             :current_page => @results[:current_page],
                                             :search_index => options[:search_index]
                                           })
  else
    Spree::Amazon::ProductCollection.empty_build
  end
end

Instance Method Details

- (Boolean) available?



104
105
106
# File 'app/models/spree/amazon/product.rb', line 104

def available?
  true
end

- (Boolean) has_stock?



112
113
114
# File 'app/models/spree/amazon/product.rb', line 112

def has_stock?
  true
end

- (Boolean) has_variants?



100
101
102
# File 'app/models/spree/amazon/product.rb', line 100

def has_variants?
  !@variants.blank?
end

- (Object) master



116
117
118
# File 'app/models/spree/amazon/product.rb', line 116

def master
  self
end

- (Object) possible_promotions



108
109
110
# File 'app/models/spree/amazon/product.rb', line 108

def possible_promotions
  [ false ]
end

- (Object) save_to_spree

Save amazon product to base or find on amazon id



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/spree/amazon/product.rb', line 68

def save_to_spree
  ::Product.save_from_amazon({
                               :attributes =>{
                                 :amazon_id      => self.id,
                                 :sku            => self.id,
                                 :name           => self.name,
                                 :count_on_hand  => 10,
                                 :available_on   => 1.day.ago,
                                 :description    => self.description,
                                 :price          => self.price.to_f
                               },

                               :price => self.price.to_f,
                               :images => self.images

                             })
end

- (Object) to_param



129
130
131
# File 'app/models/spree/amazon/product.rb', line 129

def to_param
  "#{self.id}"
end