-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1-3-stable: using quoted translation table name from product model Fix for SQL injections, use ActiveRecord querying Search for Spree 1.2 updated logic Update spree version to 1.2.x Multilingual search. Ref #4
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Spree::Core::Search::Base.class_eval do | ||
def get_products_conditions_for(base_scope, query) | ||
if query.blank? | ||
base_scope | ||
else | ||
conditions = [] | ||
keywords = [] | ||
query.split.each do |keyword| | ||
[:name, :description].map do |field| | ||
conditions << "`#{Spree::Product.translations_table_name}`.#{field} LIKE ?" | ||
keywords << "%#{keyword}%" | ||
end | ||
end | ||
base_scope.where(conditions.join(' OR '), *keywords) | ||
end | ||
end | ||
|
||
protected | ||
|
||
def get_base_scope_with_multi_lingual | ||
base_scope = Spree::Product.active.joins(:translations).where("locale = ?", I18n.locale) | ||
base_scope.merge(get_base_scope_without_multi_lingual) | ||
end | ||
|
||
alias_method_chain :get_base_scope, :multi_lingual | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::Core::Search::Base do | ||
|
||
before do | ||
include ::Spree::ProductFilters | ||
@product1 = create(:product, :name => "RoR Shirt", :name_fr => "RoR Chemise", :name_es => "RoR Camisa", :price => 9.00, :on_hand => 1) | ||
@product2 = create(:product, :name => "Trouser", :name_fr => "Pantalon", :name_es => "Pantalones", :price => 9.00, :on_hand => 1) | ||
end | ||
|
||
it "returns all products by default" do | ||
params = { :per_page => "" } | ||
searcher = Spree::Core::Search::Base.new(params) | ||
searcher.retrieve_products.count.should == 2 | ||
end | ||
|
||
it 'can return translated product name with correct i18n' do | ||
params = { :per_page => "", | ||
:keywords => 'Camisa' } | ||
I18n.locale = :es | ||
searcher = Spree::Core::Search::Base.new(params) | ||
searcher.retrieve_products.should == [@product1] | ||
end | ||
|
||
it 'should not return with incorrect i18n' do | ||
params = { :per_page => "", | ||
:keywords => 'Camisa' } | ||
I18n.locale = :fr | ||
searcher = Spree::Core::Search::Base.new(params) | ||
searcher.retrieve_products.should == [] | ||
end | ||
|
||
it 'should not return product base attribute name' do | ||
params = { :per_page => "", | ||
:keywords => 'Shirt' } | ||
I18n.locale = :fr | ||
searcher = Spree::Core::Search::Base.new(params) | ||
searcher.retrieve_products.should == [] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters