diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb
index 7b25a38..d2ced2c 100644
--- a/app/controllers/public/search_controller.rb
+++ b/app/controllers/public/search_controller.rb
@@ -122,8 +122,11 @@ class SearchController < ApplicationController
end
def sellers
+ @categories = ProductCategory.find(:all)
+ @regions = Region.find(:all).select{|r|r.lat && r.lng}
+ @product_category = ProductCategory.find(params[:category]) if params[:category]
+ @region = Region.find(params[:region]) if params[:region]
options = {}
- @product_category = ProductCategory.find_by_path(params[:product_category].join('/')) if params[:product_category]
options.merge!({:include => :products, :conditions => ['products.product_category_id = ?', @product_category.id]}) if @product_category
options.merge!({:origin => [params[:lat].to_f, params[:long].to_f], :within => params[:radius] }) if params[:lat] && params[:long] && params[:radius]
@enterprises = Enterprise.find(:all, options)
diff --git a/app/views/search/sellers.rhtml b/app/views/search/sellers.rhtml
new file mode 100644
index 0000000..4190126
--- /dev/null
+++ b/app/views/search/sellers.rhtml
@@ -0,0 +1,26 @@
+
+<% if @product_category %>
+ <% if params[:lat] && params[:long] && params[:radius] %>
+ <%= _('Listing sellers of %s witin %s km from %s %s') % [@product_category.name, params[:radius], params[:lat], params[:long]] %>
+ <% else %>
+ <%= _('Listing sellers of %s') % @product_category.name %>
+ <% end %>
+<% else %>
+ <% if params[:lat] && params[:long] && params[:radius] %>
+ <%= _('Listing sellers witin %s km from %s %s') % [params[:radius], params[:lat], params[:long]] %>
+ <% else %>
+ <%= _('Listing sellers') %>
+ <% end %>
+<% end %>
+
+
+<% form_tag({}, {:method => 'get'}) do %>
+ <%= _('Category: ') %> <%= select_tag 'category', options_from_collection_for_select(@categories, :id, :name, @product_category) %>
+ <%= _('Distance form point: ') %> <%= text_field_tag 'radius' %>
+ <%= _('Region') %> <%= select_tag 'region', options_from_collection_for_select(@regions, :id, :name, @region) %>
+ <%= submit_tag _('Search') %>
+<% end %>
+
+
+
<%= render :partial => 'profile', :collection => @enterprises %>
+
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index 7dc9625..4650e5f 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -759,6 +759,16 @@ class SearchControllerTest < Test::Unit::TestCase
assert_not_includes assigns(:results)[:comments], comment4
end
+ should 'list all sellers' do
+ ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1')
+ ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2')
+
+ get :sellers
+
+ assert_includes assigns('enterprises'), ent1
+ assert_includes assigns('enterprises'), ent2
+ end
+
should 'find enterprise by product category' do
ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1')
prod_cat = ProductCategory.create!(:name => 'pc-test', :environment => Environment.default)
@@ -766,7 +776,7 @@ class SearchControllerTest < Test::Unit::TestCase
ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2')
- get :sellers, :product_category => ['pc-test']
+ get :sellers, :category => prod_cat.id
assert_includes assigns('enterprises'), ent1
assert_not_includes assigns('enterprises'), ent2
--
libgit2 0.21.2