Class: SpreeEcs::Product

Inherits:
Base
  • Object
show all
Defined in:
lib/spree_ecs/product.rb

Class Method Summary collapse

Methods inherited from Base

cache, log

Class Method Details

.find(asin, options = { }) ⇒ Object

Find product by asin



27
28
29
30
31
32
# File 'lib/spree_ecs/product.rb', line 27

def find(asin, options={ })
  cache("spree_ecs:product:find:#{asin}:#{options.stringify_keys.sort}") do
    log("find product asin:#{asin} || options: #{options.inspect}")
    mapped(Amazon::Ecs.item_lookup(asin, ({ :response_group => "Large, Accessories" }).merge(options)).items.first)
  end
end

.multi_find(asins, options = { }) ⇒ Object

MultiFind product by asin



36
37
38
39
40
41
# File 'lib/spree_ecs/product.rb', line 36

def multi_find(asins, options={ })
  cache("spree_ecs:product:multifind:#{asins}:#{options.stringify_keys.sort}") do
    log(" multi find product asin:#{asins} || options: #{options.inspect}")
    Amazon::Ecs.item_lookup(asins, ({ :response_group => "Large, Accessories" }).merge(options)).items.map{|v| mapped(v) }
  end
end

.search(options = { }) ⇒ Object

Search products



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/spree_ecs/product.rb', line 8

def search(options={ })

  @query = options.delete(:q) || (options[:browse_node] ? '' : '*')
  @options = (Spree::Config.amazon_options[:query][:options]).merge(options)
  @options.delete(:sort) if @options[:search_index] && @options[:search_index].to_s == 'All'
  @query = Spree::Config.amazon_options[:query][:q].to_s.gsub("%{q}", @query )
  cache("spree_ecs:product:search:#{@query }:#{@options.stringify_keys.sort}" ) {
    log "search products query:#{ @query} || options #{options.inspect}"
    @response = Amazon::Ecs.item_search(@query, @options)
    {
      :total_entries => @response.total_pages,
      :current_page => (@response.item_page.to_i == 0 ? 1 : @response.item_page.to_i),
      :products => @response.items.map{ |item| mapped(item) }
    }
  }
end