spree_sunspot 0.70.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -9,7 +9,7 @@ Basic Installation
9
9
 
10
10
  1. Add the following to your Gemfile
11
11
  <pre>
12
- gem 'spree_sunspot', '~> 0.70.0'
12
+ gem 'spree_sunspot', '~> 1.0.0'
13
13
  </pre>
14
14
  2. Run `bundle install`
15
15
  3. lunch installation:
@@ -23,4 +23,4 @@ Example
23
23
 
24
24
  COMING SOON
25
25
 
26
- Copyright (c) 2012 [Damiano Giacomello], released under the New BSD License
26
+ Copyright (c) 2012 [Damiano Giacomello], released under the New BSD License
@@ -1,3 +1,3 @@
1
- AppConfiguration.class_eval do
1
+ Spree::AppConfiguration.class_eval do
2
2
  preference :total_similar_products, :integer, :default => 10
3
- end
3
+ end
@@ -0,0 +1,20 @@
1
+ Spree::Product.class_eval do
2
+ def get_option_values(option_name)
3
+ sql = <<-eos
4
+ SELECT DISTINCT ov.id, ov.presentation
5
+ FROM spree_option_values AS ov
6
+ LEFT JOIN spree_option_types AS ot ON (ov.option_type_id = ot.id)
7
+ LEFT JOIN spree_option_values_variants AS ovv ON (ovv.option_value_id = ov.id)
8
+ LEFT JOIN spree_variants AS v ON (ovv.variant_id = v.id)
9
+ LEFT JOIN spree_products AS p ON (v.product_id = p.id)
10
+ WHERE ((ot.name = '#{option_name}' OR ot.presentation = '#{option_name}')
11
+ AND p.id = #{self.id});
12
+ eos
13
+ Spree::OptionValue.find_by_sql(sql).map(&:presentation)
14
+ end
15
+ end
16
+
17
+ unless SpreeSunspot::Setup.configuration.nil?
18
+ Spree::Product.class_eval &SpreeSunspot::Setup.configuration
19
+ end
20
+
@@ -0,0 +1 @@
1
+ <%= render :partial => "spree/shared/search_results", :locals => { :products => @products, :searcher => @searcher } %>
@@ -6,8 +6,8 @@
6
6
  <%= link_to I18n.t(:clear_all), '#', :class => 'filter_clear_all' %>
7
7
  <% filter_params.each do |filter| %>
8
8
  <% next unless filter.display? %>
9
- <% if lookup_context.find_all("filters/_#{filter.display_param}").any? %>
10
- <%= render :partial => "filters/#{filter.display_param}", :locals => { :filter => filter }%>
9
+ <% if lookup_context.find_all("spree/filters/_#{filter.display_param}").any? %>
10
+ <%= render :partial => "spree/filters/#{filter.display_param}", :locals => { :filter => filter }%>
11
11
  <% else %>
12
12
  <fieldset class="filter" data-field="<%= filter.display_param %>">
13
13
  <legend class="sub-header"><%= filter.display_name %></legend>
@@ -0,0 +1,11 @@
1
+ <% content_for :sidebar do %>
2
+ <div data-hook="homepage_sidebar_navigation">
3
+ <%= render :partial => 'spree/shared/taxonomies' %>
4
+ </div>
5
+ <% end %>
6
+
7
+ <% if @products.empty? %>
8
+ <%= t(:empty_search_results) %>
9
+ <% else %>
10
+ <%= render :partial => "spree/shared/products", :locals => { :products => products }%>
11
+ <% end %>
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
- Rails.application.routes.draw do
1
+ Spree::Core::Engine.routes.prepend do
2
2
  match "/q" => "home#filter"
3
3
  match "/products/q" => "products#filter"
4
- match "/:id/q" => "taxons#filter", :constraints => { :id => Regexp.new('(' + Taxon.all.collect { |b| b.linkname rescue b.permalink }.join('|') + ')') }
4
+ match "/:id/q" => "taxons#filter", :constraints => { :id => Regexp.new('(' + Spree::Taxon.all.collect { |b| b.linkname rescue b.permalink }.join('|') + ')') }
5
5
  end
@@ -9,11 +9,11 @@ module SpreeSunspot
9
9
  def self.source_root
10
10
  @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
11
11
  end
12
-
12
+
13
13
  def invoke_sunspot_rails_generator
14
14
  SunspotRails::Generators::InstallGenerator.start
15
15
  end
16
-
16
+
17
17
  def copy_initializer_file
18
18
  copy_file "spree_sunspot.rb", "config/initializers/spree_sunspot.rb"
19
19
  end
@@ -3,7 +3,7 @@ SpreeSunspot::Setup.configure do
3
3
  text :name, :boost => 2.0
4
4
  text :description, :boost => 1.2
5
5
  time :available_on
6
- integer :taxon_ids, :references => Taxon, :multiple => true do
6
+ integer :taxon_ids, :references => Spree::Taxon, :multiple => true do
7
7
  taxons.collect{|t| t.self_and_ancestors.map(&:id) }.flatten
8
8
  end
9
9
  string :taxon_names, :multiple => true do
@@ -16,11 +16,11 @@ SpreeSunspot::Setup.configure do
16
16
  # Additional Examples
17
17
  #
18
18
  # string :category_names, :multiple => true do
19
- # category = Taxon.find_by_permalink('categories')
19
+ # category = Spree::Taxon.find_by_permalink('categories')
20
20
  # taxons.select{|t| t.ancestors.include?(category)}.collect{|t| t.self_and_ancestors.map(&:name)}.flatten - [category.name]
21
21
  # end
22
22
  # string :brand_name do
23
- # brand = Taxon.find_by_permalink('brands')
23
+ # brand = Spree::Taxon.find_by_permalink('brands')
24
24
  # t = taxons.select{|t| t.ancestors.include?(brand)}.first
25
25
  # t.name unless t.nil?
26
26
  # end
@@ -40,12 +40,12 @@ SpreeSunspot::Setup.filters do |filters|
40
40
  # filters.add do |f|
41
41
  # f.search_param = 'category_name'
42
42
  # f.display_name = 'Category'
43
- # f.values { Taxon.find_by_permalink('categories').children.map(&:name) }
43
+ # f.values { Spree::Taxon.find_by_permalink('categories').children.map(&:name) }
44
44
  # end
45
45
  #
46
46
  # filters.add do |f|
47
47
  # f.search_param = 'brand_name'
48
48
  # f.display_name = 'Brand'
49
- # f.values { Taxon.find_by_permalink('brands').children.map(&:name) }
49
+ # f.values { Spree::Taxon.find_by_permalink('brands').children.map(&:name) }
50
50
  # end
51
51
  end
@@ -16,25 +16,21 @@ module SpreeSunspot
16
16
  Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
17
17
  Rails.configuration.cache_classes ? require(c) : load(c)
18
18
  end
19
-
19
+
20
20
  ActionView::Base.class_eval do
21
21
  include SpreeSunspot::FilterSupport::Helpers
22
22
  end
23
23
  end
24
24
 
25
25
  config.to_prepare &method(:activate).to_proc
26
- #ActionView::Base.class_eval { include SpreeSunspot::FilterSupport::Helpers }
27
- #ActionController::Base.class_eval do
28
- # include(SpreeSunspot::FilterSupport)
29
- # filter_support
30
- #end
31
-
32
- initializer "spree.sunspot.search_config", :after => "spree.environment" do |app|
26
+
27
+ initializer "spree.sunspot.search_config", :after => "spree.load_preferences" do |app|
33
28
  Spree::BaseController.class_eval do
34
29
  include(SpreeSunspot::FilterSupport)
35
30
  filter_support
36
31
  end
37
- Spree::Config.searcher_class = SpreeSunspot::Search
32
+
33
+ app.config.spree.preferences.searcher_class = SpreeSunspot::Search
38
34
  end
39
35
  end
40
36
  end
@@ -5,22 +5,22 @@ module SpreeSunspot
5
5
  def self.included(base)
6
6
  base.extend(ClassMethods)
7
7
  end
8
-
8
+
9
9
  module ClassMethods
10
10
  def filter_support(options = {})
11
11
  additional_params = options[:additional_params_method]
12
12
  class_eval <<-EOV
13
- include SpreeSunspot::FilterSupport::InstanceMethods
14
- include SpreeSunspot::FilterSupport::Helpers
15
- helper_method :render_filter
13
+ include SpreeSunspot::FilterSupport::InstanceMethods
14
+ include SpreeSunspot::FilterSupport::Helpers
15
+ helper_method :render_filter
16
16
  EOV
17
17
  end
18
18
  end
19
-
19
+
20
20
  module InstanceMethods
21
21
  def filter
22
22
  if params[:id]
23
- taxon = Taxon.find_by_linkname(params[:id])
23
+ taxon = Spree::Taxon.find_by_linkname(params[:id])
24
24
  if taxon
25
25
  params.merge!(:taxon => taxon)
26
26
  end
@@ -29,7 +29,7 @@ module SpreeSunspot
29
29
  respond_with(@products)
30
30
  end
31
31
  end
32
-
32
+
33
33
  def search_for_products(scope=nil)
34
34
  if (params[:s].nil? or params[:s].empty?) and !params[:source_url].nil?
35
35
  redirect_to params[:source_url]
@@ -43,12 +43,12 @@ module SpreeSunspot
43
43
  end
44
44
  return true
45
45
  end
46
-
46
+
47
47
  def search_for_similar_products(product, *field_names)
48
48
  @searcher = Spree::Config.searcher_class.new(params)
49
49
  @similar_products = @searcher.similar_products(product, *field_names)
50
50
  end
51
-
51
+
52
52
  def filter_url_options
53
53
  object = instance_variable_get('@'+controller_name.singularize)
54
54
  if object
@@ -63,11 +63,11 @@ module SpreeSunspot
63
63
  end
64
64
  end
65
65
  end
66
-
66
+
67
67
  module Helpers
68
68
  def render_filter
69
69
  filter_params = SpreeSunspot::Setup.filters.filters
70
- render :partial => 'shared/filter', :locals => { :filter_params => filter_params }
70
+ render :partial => 'spree/shared/filter', :locals => { :filter_params => filter_params }
71
71
  end
72
72
  end
73
73
  end
@@ -1,22 +1,22 @@
1
1
  module SpreeSunspot
2
2
  class Filters
3
3
  attr_accessor :filters
4
-
4
+
5
5
  def initialize
6
6
  @filters = []
7
7
  end
8
-
8
+
9
9
  def add(&blk)
10
10
  filter = SpreeSunspot::Filter::Filter.new
11
11
  yield filter
12
12
  filter.finalize!
13
13
  filters << filter
14
14
  end
15
-
15
+
16
16
  def filter_for(display_name)
17
17
  @filters.select{|f| f.display_name == display_name or f.display_param == display_name }.first
18
18
  end
19
-
19
+
20
20
  def method_missing(method, *args)
21
21
  if @filters.respond_to?(method)
22
22
  @filters.send(method, *args)
@@ -1,8 +1,8 @@
1
- require 'spree/search/base'
1
+ require 'spree/core/search/base'
2
2
  require 'spree_sunspot/filter/filter'
3
3
 
4
4
  module SpreeSunspot
5
- class Search < Spree::Search::Base
5
+ class Search < Spree::Core::Search::Base
6
6
  def query
7
7
  @filter_query
8
8
  end
@@ -39,9 +39,9 @@ module SpreeSunspot
39
39
  hits = []
40
40
  if products_search.total > 0
41
41
  hits = products_search.hits.collect{|hit| hit.primary_key.to_i}
42
- base_scope = base_scope.where ["#{Product.table_name}.id in (?)", hits]
42
+ base_scope = base_scope.where ["#{Spree::Product.table_name}.id in (?)", hits]
43
43
  else
44
- base_scope = base_scope.where ["#{Product.table_name}.id = -1"]
44
+ base_scope = base_scope.where ["#{Spree::Product.table_name}.id = -1"]
45
45
  end
46
46
  products_scope = @product_group.apply_on(base_scope)
47
47
  products_results = products_scope.includes([:images, :master]).page(1)
@@ -52,32 +52,34 @@ module SpreeSunspot
52
52
 
53
53
  protected
54
54
  def get_base_scope
55
- base_scope = get_common_base_scope
55
+ base_scope = @cached_product_group ? @cached_product_group.products.active : Spree::Product.active
56
56
  base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
57
57
  base_scope = get_products_conditions_for(base_scope, keywords) unless keywords.blank?
58
-
59
- # TODO order by master price if is preferred
58
+
60
59
  #base_scope = base_scope.ascend_by_master_price
60
+ base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
61
+ base_scope = base_scope.group_by_products_id if @product_group.product_scopes.size > 1
61
62
  base_scope
62
63
  end
63
64
 
64
65
  def get_products_conditions_for(base_scope, query)
65
- @search = Sunspot.new_search(Product) do |q|
66
+ @search = Sunspot.new_search(Spree::Product) do |q|
66
67
  q.keywords(query) unless query.blank?
67
68
  # There is no option to say don't paginate.
68
69
  #q.paginate(:page => 1, :per_page => 1000000)
69
70
  end
70
-
71
+
71
72
  if !@properties[:filters].blank?
72
73
  @filter_query = SpreeSunspot::Filter::Query.new(@properties[:filters])
73
74
  @search = @filter_query.build_search(@search)
74
75
  end
76
+
75
77
  @search.execute
76
78
  if @search.total > 0
77
79
  hits = @search.hits.collect{|hit| hit.primary_key.to_i}
78
- base_scope = base_scope.where ["#{Product.table_name}.id in (?)", hits]
80
+ base_scope = base_scope.where ["#{Spree::Product.table_name}.id in (?)", hits]
79
81
  else
80
- base_scope = base_scope.where ["#{Product.table_name}.id = -1"]
82
+ base_scope = base_scope.where ["#{Spree::Product.table_name}.id = -1"]
81
83
  end
82
84
  base_scope
83
85
  end
@@ -87,14 +89,5 @@ module SpreeSunspot
87
89
  @properties[:filters] = params[:s] || params['s'] || []
88
90
  @properties[:total_similar_products] = params[:total_similar_products].to_i > 0 ? params[:total_similar_products].to_i : Spree::Config[:total_similar_products]
89
91
  end
90
-
91
- private
92
- def get_common_base_scope
93
- base_scope = @cached_product_group ? @cached_product_group.products.active : Product.active
94
- base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
95
- base_scope = base_scope.group_by_products_id if @product_group.product_scopes.size > 1
96
- base_scope
97
- end
98
-
99
92
  end
100
93
  end
@@ -7,16 +7,16 @@ module SpreeSunspot
7
7
  include Singleton
8
8
  IGNORE_MAX = 1000000000
9
9
  @@filters = SpreeSunspot::Filters.new
10
-
10
+
11
11
  @@configuration = nil
12
12
  def self.configure(&blk)
13
13
  @@configuration = blk
14
14
  end
15
-
15
+
16
16
  def self.configuration
17
17
  @@configuration
18
18
  end
19
-
19
+
20
20
  def self.filters(&blk)
21
21
  yield @@filters if block_given?
22
22
  @@filters
@@ -1,8 +1,8 @@
1
1
  namespace :spree_sunspot do
2
2
  desc "Reindex all products"
3
3
  task :reindex => :environment do
4
- Product.remove_all_from_index!
5
- Product.reindex
4
+ Spree::Product.remove_all_from_index!
5
+ Spree::Product.reindex
6
6
  Sunspot.commit
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_sunspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.70.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -100,12 +100,11 @@ files:
100
100
  - app/assets/stylesheets/admin/spree_sunspot.css
101
101
  - app/assets/stylesheets/store/filters.css.erb
102
102
  - app/assets/stylesheets/store/spree_sunspot.css
103
- - app/models/app_configuration_decorator.rb
104
- - app/models/product_decorator.rb
105
- - app/views/base/filter.html.erb
106
- - app/views/home/filter.html.erb
107
- - app/views/shared/_filter.html.erb
108
- - app/views/shared/_search_results.html.erb
103
+ - app/models/spree/app_configuration_decorator.rb
104
+ - app/models/spree/product_decorator.rb
105
+ - app/views/spree/base/filter.html.erb
106
+ - app/views/spree/shared/_filter.html.erb
107
+ - app/views/spree/shared/_search_results.html.erb
109
108
  - config/locales/en.yml
110
109
  - config/locales/it.yml
111
110
  - config/routes.rb
@@ -1,20 +0,0 @@
1
- Product.class_eval do
2
- def get_option_values(option_name)
3
- sql = <<-eos
4
- SELECT DISTINCT ov.id, ov.presentation
5
- FROM option_values AS ov
6
- LEFT JOIN option_types AS ot ON (ov.option_type_id = ot.id)
7
- LEFT JOIN option_values_variants AS ovv ON (ovv.option_value_id = ov.id)
8
- LEFT JOIN variants AS v ON (ovv.variant_id = v.id)
9
- LEFT JOIN products AS p ON (v.product_id = p.id)
10
- WHERE ((ot.name = '#{option_name}' OR ot.presentation = '#{option_name}')
11
- AND p.id = #{self.id});
12
- eos
13
- OptionValue.find_by_sql(sql).map(&:presentation)
14
- end
15
- end
16
-
17
- unless SpreeSunspot::Setup.configuration.nil?
18
- Product.class_eval &SpreeSunspot::Setup.configuration
19
- end
20
-
@@ -1 +0,0 @@
1
- <%= render :partial => "shared/search_results", :locals => { :products => @products, :searcher => @searcher } %>
@@ -1 +0,0 @@
1
- <%= render :partial => "shared/search_results", :locals => { :products => @products, :searcher => @searcher } %>
@@ -1,11 +0,0 @@
1
- <% content_for :sidebar do %>
2
- <div data-hook="homepage_sidebar_navigation">
3
- <%= render :partial => 'shared/taxonomies' %>
4
- </div>
5
- <% end %>
6
-
7
- <% if @products.blank? %>
8
- <%= t(:empty_search_results) %>
9
- <% else %>
10
- <%= render :partial => "shared/products", :locals => { :products => @products }%>
11
- <% end %>