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

#bindsObject

Returns the value of attribute binds



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

def binds
  @binds
end

#created_atObject

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

#descriptionObject

Returns the value of attribute description



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

def description
  @description
end

#idObject

Returns the value of attribute id



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

def id
  @id
end

#imagesObject

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

#nameObject

Returns the value of attribute name



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

def name
  @name
end

#priceObject

Returns the value of attribute price



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

def price
  @price
end

#propsObject

Returns the value of attribute props



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

def props
  @props
end

#props_strObject

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

#sale_propsObject

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

#taxon_idObject

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

#taxon_nameObject

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

#taxonsObject

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

#updated_atObject

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

#urlObject

Returns the value of attribute url



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

def url
  @url
end

#variant_attributesObject

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

#variant_optionsObject

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

#variantsObject

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

.class_nameObject



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

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

.find(product_asin) ⇒ Object

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

.multi_find(asins) ⇒ Object



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

.nameObject



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

def name
  "Product"
end

.prepare_id(product_id) ⇒ Object



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

def prepare_id(product_id)
  product_id.to_s
end

.root_page(options) ⇒ Object

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

.save_to_spree_or_find(amazon_id_or_id) ⇒ Object



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

.search(options = { }) ⇒ Object

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

#available?Boolean



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

def available?
  true
end

#has_stock?Boolean



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

def has_stock?
  true
end

#has_variants?Boolean



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

def has_variants?
  !@variants.blank?
end

#masterObject



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

def master
  self
end

#possible_promotionsObject



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

def possible_promotions
  [ false ]
end

#save_to_spreeObject

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

#to_paramObject



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

def to_param
  "#{self.id}"
end