diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 69868ca..f797c08 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -155,12 +155,9 @@ class SearchController < ApplicationController def products @results[:products].uniq! - @categories = ProductCategory.menu_categories(@product_category) - @categories.map do |cat| + @categories_menu = ProductCategory.menu_categories(@product_category, environment).map do |cat| [cat, @finder.count(:products, @filtered_query, calculate_find_options(:products, nil, cat, @region, params[:radius]))] - end - - @found_product_categories = @counts.values.sort_by{|v|v[0].full_name} + end.select{|cat, hits| hits > 0 } end alias :assets :index diff --git a/app/models/product_category.rb b/app/models/product_category.rb index ce91b4f..c9e619c 100644 --- a/app/models/product_category.rb +++ b/app/models/product_category.rb @@ -10,4 +10,8 @@ class ProductCategory < Category def all_products Product.find(:all, :conditions => { :product_category_id => tree.map(&:id) }) end + + def self.menu_categories(top_category, env) + top_category ? top_category.children : top_level_for(env) + end end diff --git a/app/views/search/products.rhtml b/app/views/search/products.rhtml index a860313..966f240 100644 --- a/app/views/search/products.rhtml +++ b/app/views/search/products.rhtml @@ -12,10 +12,10 @@ <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> -<% if @found_product_categories %> +<% if @categories_menu %>