Class: Spree::Core::Search::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/spree/core/search/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
# File 'lib/spree/core/search/base.rb', line 11

def initialize(params)
  self.pricing_options = Spree::Config.default_pricing_options
  @properties = {}
  prepare(params)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/spree/core/search/base.rb', line 38

def method_missing(name)
  if @properties.key? name
    @properties[name]
  else
    super
  end
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



8
9
10
# File 'lib/spree/core/search/base.rb', line 8

def current_user
  @current_user
end

#pricing_optionsObject

Returns the value of attribute pricing_options.



9
10
11
# File 'lib/spree/core/search/base.rb', line 9

def pricing_options
  @pricing_options
end

#propertiesObject

Returns the value of attribute properties.



7
8
9
# File 'lib/spree/core/search/base.rb', line 7

def properties
  @properties
end

Instance Method Details

#current_currencyObject



23
24
25
# File 'lib/spree/core/search/base.rb', line 23

def current_currency
  pricing_options.currency
end

#current_currency=(currency) ⇒ Object



17
18
19
20
21
# File 'lib/spree/core/search/base.rb', line 17

def current_currency=(currency)
  self.pricing_options = Spree::Config.pricing_options_class.new(
    pricing_options.desired_attributes.merge(currency: currency)
  )
end

#retrieve_productsObject



28
29
30
31
32
33
34
35
36
# File 'lib/spree/core/search/base.rb', line 28

def retrieve_products
  @products = get_base_scope
  curr_page = page || 1

  unless Spree::Config.show_products_without_price
    @products = @products.joins(:prices).merge(Spree::Price.where(pricing_options.search_arguments)).distinct
  end
  @products = @products.page(curr_page).per(per_page)
end