diff --git a/app/controllers/spree/distributors_controller.rb b/app/controllers/spree/distributors_controller.rb new file mode 100644 index 0000000000..e44d8251e7 --- /dev/null +++ b/app/controllers/spree/distributors_controller.rb @@ -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 diff --git a/app/controllers/spree/suppliers_controller.rb b/app/controllers/spree/suppliers_controller.rb new file mode 100644 index 0000000000..5591b30156 --- /dev/null +++ b/app/controllers/spree/suppliers_controller.rb @@ -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 diff --git a/app/models/spree/distributor.rb b/app/models/spree/distributor.rb index f7f87617d5..6cdbf7a616 100644 --- a/app/models/spree/distributor.rb +++ b/app/models/spree/distributor.rb @@ -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 diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 8de3cdfa1b..0eb763f297 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -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 diff --git a/app/models/spree/supplier.rb b/app/models/spree/supplier.rb index b585a994f6..3c8c9844b6 100644 --- a/app/models/spree/supplier.rb +++ b/app/models/spree/supplier.rb @@ -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 diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index 099b652800..a9b501b4ac 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index c4ffbaf86d..65c090dd21 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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