Skip to content

Commit

Permalink
Fixed work of base simple search.
Browse files Browse the repository at this point in the history
  • Loading branch information
romul authored and schof committed Jul 12, 2010
1 parent 92fd8a4 commit 35ecaf9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion core/app/models/taxon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def applicable_filters
fs += [
ProductFilters.price_filter,
ProductFilters.brand_filter,
ProductFilters.selective_brand_filter(self) ]
#ProductFilters.selective_brand_filter(self)
]
end

# Creates permalink based on .to_url method provided by stringx gem
Expand Down
6 changes: 3 additions & 3 deletions core/lib/scopes/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ module Scopes::Product
#
# Product.taxons_id_eq(x)
#
Product.scope :in_taxon, lambda {|taxon|
Product.in_taxons(taxon).scope :find
::Product.scope :in_taxon, lambda {|taxon|
{ :joins => :taxons, :conditions => ["taxons.id IN (?) ", taxon.self_and_descendants.map(&:id)]}
}

# This scope selects products in all taxons AND all its ancestors
Expand Down Expand Up @@ -238,7 +238,7 @@ def self.get_taxons(*ids_or_records_or_names)
# specifically avoid having an order for taxon search (conflicts with main order)
def self.prepare_taxon_conditions(taxons)
conditions = taxons.map{|taxon|
taxon.self_and_descendants.scope(:find)[:conditions]
taxon.self_and_descendants.scope(:find)[:conditions].map(&:id)
}.inject([[]]){|result, scope|
result.first << scope.shift
result += scope;
Expand Down
4 changes: 2 additions & 2 deletions core/lib/spree/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def retrieve_products
@product_group = ProductGroup.new
end

@product_group.add_scope('in_taxon', @taxon) unless @taxon.blank?
@product_group.add_scope('keywords', @keywords) unless @keywords.blank?
@product_group = @product_group.from_search(params[:search]) if params[:search]

base_scope = Product.active
base_scope = base_scope.in_taxon(@taxon) unless @taxon.blank?
base_scope = base_scope.keywords(@keywords) unless @keywords.blank?
#base_scope = @cached_product_group ? @cached_product_group.products.active : Product.active
base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
@products_scope = @product_group.apply_on(base_scope)
Expand Down
3 changes: 1 addition & 2 deletions core/lib/spree/search/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ def initialize

# method should return hash with conditions {:conditions=> "..."} for Product model
def get_products_conditions_for(query)
query = query.split
Product.name_or_description_like_any(query).scope(:find)
{:conditions => ["products.name LIKE ? OR products.description LIKE ?", "%#{query}%", "%#{query}%"]}
end

def prepare(params)
Expand Down

0 comments on commit 35ecaf9

Please sign in to comment.