Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Only search for products from enabled enterprises

Also, add a facet to filter enabled/not enabled enterprises
  • Loading branch information...
commit 5268427cfc84608a1d058d054f94e6959d443518 1 parent 9986427
@brauliobo brauliobo authored
View
2  app/controllers/public/search_controller.rb
@@ -45,7 +45,7 @@ def people
def products
if !@empty_query
- full_text_search ['public:true']
+ full_text_search ['public:true', 'enabled:true']
else
@one_page = true
@geosearch = logged_in? && current_user.person.lat && current_user.person.lng
View
4 app/models/product.rb
@@ -238,7 +238,7 @@ def f_qualifier
end
alias_method :name_sortable, :name
- delegate :region, :region_id, :environment, :environment_id, :to => :enterprise
+ delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :enterprise
def name_sortable # give a different name for solr
name
end
@@ -278,7 +278,7 @@ def category_filter
{:description => :text}, {:category_full_name => :text},
# filtered fields
{:public => :boolean}, {:environment_id => :integer},
- {:category_filter => :integer},
+ {:enabled => :boolean}, {:category_filter => :integer},
# ordered/query-boosted fields
{:price_sortable => :decimal}, {:name_sortable => :string},
{:lat => :float}, {:lng => :float},
View
13 app/models/profile.rb
@@ -857,6 +857,7 @@ def self.f_categories_proc(facet, id)
def f_categories
category_ids - [region_id]
end
+
def f_region
self.region_id
end
@@ -870,6 +871,14 @@ def self.f_region_proc(id)
end
end
+ def self.f_enabled_proc(enabled)
+ enabled = enabled == "true" ? true : false
+ enabled ? _('Enabled') : _('Not enabled')
+ end
+ def f_enabled
+ self.enabled
+ end
+
def name_sortable # give a different name for solr
name
end
@@ -882,11 +891,13 @@ def category_filter
public
acts_as_faceted :fields => {
+ :f_enabled => {:label => _('Situation'), :type_if => proc { |klass| klass.kind_of?(Enterprise) },
+ :proc => proc { |id| f_enabled_proc(id) }},
:f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }},
:f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)},
:label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc{ |env| f_categories_label_abbrev_proc(env) }},
}, :category_query => proc { |c| "category_filter:#{c.id}" },
- :order => [:f_region, :f_categories]
+ :order => [:f_region, :f_categories, :f_enabled]
acts_as_searchable :fields => facets_fields_for_solr + [:extra_data_for_index,
# searched fields
View
20 test/functional/search_controller_test.rb
@@ -799,18 +799,26 @@ def asset_product_properties(product)
assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs
end
+ should 'only list products from enabled enterprises' do
+ ent1 = fast_create(Enterprise, :enabled => true)
+ ent2 = fast_create(Enterprise, :enabled => false)
+ prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent1.id, :product_category_id => @product_category.id)
+ prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent2.id, :product_category_id => @product_category.id)
+
+ get :products, :query => 'product'
+
+ assert_equal [prod1], assigns(:results)[:products].docs
+ end
+
should 'order product results by name when requested' do
ent = fast_create(Enterprise)
prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id)
prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id)
prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id)
- prod3.name = 'product A'
- prod3.save!
- prod1.name = 'product B'
- prod1.save!
- prod2.name = 'product C'
- prod2.save!
+ prod3.update_attribute! :name, 'product A'
+ prod2.update_attribute! :name, 'product B'
+ prod1.update_attribute! :name, 'product C'
get :products, :query => 'product', :order_by => :name
Please sign in to comment.
Something went wrong with that request. Please try again.