Class: Spree::Search::Amazon

Inherits:
Base
  • Object
show all
Defined in:
lib/spree/search/amazon.rb

Instance Method Summary collapse

Instance Method Details

#prepare(params) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/spree/search/amazon.rb', line 22

def prepare(params)
  @properties[:taxon] = params[:taxon].blank? ? nil : Spree::Amazon::Taxon.find(params[:taxon])
  @properties[:keywords] = params[:keywords]

  per_page = params[:per_page].to_i
  @properties[:per_page] = per_page > 0 ? per_page : Spree::Config[:products_per_page]
  @properties[:page] = (params[:page].to_i <= 0) ? 1 : params[:page].to_i
end

#retrieve_productsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/spree/search/amazon.rb', line 4

def retrieve_products
  curr_page = manage_pagination && keywords ? 1 : page
  options = {:item_page => curr_page , :page_size => 10 }

  if keywords # || @properties[:taxon].present?
    options.merge!({ :q => keywords}) if keywords
  end

  if @properties[:taxon].present?
    options.merge!({ :search_index => taxon.try(:search_index), :browse_node => taxon.try(:id) })
  end
  if options[:q].present? || @properties[:taxon].present?
    Spree::Amazon::Product.search(options)
  else
    Spree::Amazon::Product.root_page(options)
  end
end