mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Display supplier/distributor search results
This commit is contained in:
12
app/controllers/spree/distributors_controller.rb
Normal file
12
app/controllers/spree/distributors_controller.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Spree
|
||||
class DistributorsController < BaseController
|
||||
def show
|
||||
options = {:distributor_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@searcher = Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
render :template => 'spree/products/index'
|
||||
end
|
||||
end
|
||||
end
|
||||
12
app/controllers/spree/suppliers_controller.rb
Normal file
12
app/controllers/spree/suppliers_controller.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Spree
|
||||
class SuppliersController < BaseController
|
||||
def show
|
||||
options = {:supplier_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@searcher = Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
render :template => 'spree/products/index'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -12,5 +12,9 @@ module Spree
|
||||
def initialize_country
|
||||
self.country = Spree::Country.find_by_id(Spree::Config[:default_country_id])
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{name.parameterize}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,5 +7,5 @@ Spree::Product.class_eval do
|
||||
validates_presence_of :distributors
|
||||
|
||||
scope :in_supplier, lambda { |supplier| where(:supplier_id => supplier) }
|
||||
scope :in_distributor, lambda { |distributor| joins(:distributors).where('distributors.id = ?', distributor) }
|
||||
scope :in_distributor, lambda { |distributor_id| joins(:distributors).where('distributors.id = ?', distributor_id.to_i) }
|
||||
end
|
||||
|
||||
@@ -12,5 +12,9 @@ module Spree
|
||||
def initialize_country
|
||||
self.country = Spree::Country.find_by_id(Spree::Config[:default_country_id])
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{name.parameterize}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
%h6.filter_name Shop by Supplier
|
||||
%ul.filter_choices
|
||||
- @suppliers.each do |supplier|
|
||||
%li.nowrap= link_to supplier.name, "#"
|
||||
%li.nowrap= link_to supplier.name, supplier
|
||||
|
||||
%h6.filter_name Shop by Distributor
|
||||
%ul.filter_choices
|
||||
- @distributors.each do |distributor|
|
||||
%li.nowrap= link_to distributor.name, "#"
|
||||
%li.nowrap= link_to distributor.name, distributor
|
||||
|
||||
@@ -1,68 +1,13 @@
|
||||
Openfoodweb::Application.routes.draw do
|
||||
# resources :distributors
|
||||
|
||||
# Mount Spree's routes
|
||||
mount Spree::Core::Engine, :at => '/'
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
||||
# Sample of regular route:
|
||||
# match 'products/:id' => 'catalog#view'
|
||||
# Keep in mind you can assign values other than :controller and :action
|
||||
|
||||
# Sample of named route:
|
||||
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
||||
# This route can be invoked with purchase_url(:id => product.id)
|
||||
|
||||
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
||||
# resources :products
|
||||
|
||||
# Sample resource route with options:
|
||||
# resources :products do
|
||||
# member do
|
||||
# get 'short'
|
||||
# post 'toggle'
|
||||
# end
|
||||
#
|
||||
# collection do
|
||||
# get 'sold'
|
||||
# end
|
||||
# end
|
||||
|
||||
# Sample resource route with sub-resources:
|
||||
# resources :products do
|
||||
# resources :comments, :sales
|
||||
# resource :seller
|
||||
# end
|
||||
|
||||
# Sample resource route with more complex sub-resources
|
||||
# resources :products do
|
||||
# resources :comments
|
||||
# resources :sales do
|
||||
# get 'recent', :on => :collection
|
||||
# end
|
||||
# end
|
||||
|
||||
# Sample resource route within a namespace:
|
||||
# namespace :admin do
|
||||
# # Directs /admin/products/* to Admin::ProductsController
|
||||
# # (app/controllers/admin/products_controller.rb)
|
||||
# resources :products
|
||||
# end
|
||||
|
||||
# You can have the root of your site routed with "root"
|
||||
# just remember to delete public/index.html.
|
||||
# root :to => 'welcome#index'
|
||||
|
||||
# See how all your routes lay out with "rake routes"
|
||||
|
||||
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
||||
# Note: This route will make all actions in every controller accessible via GET requests.
|
||||
# match ':controller(/:action(/:id(.:format)))'
|
||||
end
|
||||
|
||||
|
||||
Spree::Core::Engine.routes.prepend do
|
||||
resources :suppliers
|
||||
resources :distributors
|
||||
|
||||
namespace :admin do
|
||||
resources :distributors
|
||||
resources :suppliers
|
||||
|
||||
Reference in New Issue
Block a user