diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 1b05eaf1c3..1290530ddd 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -26,28 +26,4 @@ class EnterprisesController < BaseController @searcher = Spree::Config.searcher_class.new(options) @products = @searcher.retrieve_products end - - def select_distributor - distributor = Enterprise.is_distributor.find params[:id] - - order = current_order(true) - - if order.can_change_distributor? - order.distributor = distributor - order.save! - end - - redirect_to distributor - end - - def deselect_distributor - order = current_order(true) - - if order.can_change_distributor? - order.distributor = nil - order.save! - end - - redirect_to root_path - end end diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 90b851fbaf..798eedd60a 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -30,6 +30,29 @@ Spree::OrdersController.class_eval do end end + def select_distributor + distributor = Enterprise.is_distributor.find params[:id] + + order = current_order(true) + + if order.can_change_distributor? + order.distributor = distributor + order.save! + end + + redirect_to main_app.enterprise_path(distributor) + end + + def deselect_distributor + order = current_order(true) + + if order.can_change_distributor? + order.distributor = nil + order.save! + end + + redirect_to root_path + end private diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index bd25db53a0..41da860f88 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -12,10 +12,10 @@ - @distributors.each do |distributor| %li.nowrap - if order.nil? || order.can_change_distributor? - = link_to distributor.name, main_app.select_distributor_enterprise_path(distributor) + = link_to distributor.name, select_distributor_order_path(distributor) - elsif order.distributor == distributor = link_to distributor.name, [main_app, distributor] - else %span.inactive= distributor.name - if current_distributor && order.can_change_distributor? - = button_to 'Browse All Distributors', main_app.deselect_distributor_enterprises_path, :method => :get + = button_to 'Browse All Distributors', deselect_distributor_orders_path, :method => :get diff --git a/config/routes.rb b/config/routes.rb index 60454a3ae1..1c7abf560c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,8 +4,6 @@ Openfoodweb::Application.routes.draw do resources :enterprises do get :suppliers, :on => :collection get :distributors, :on => :collection - get :select_distributor, :on => :member - get :deselect_distributor, :on => :collection end namespace :admin do @@ -25,4 +23,9 @@ Spree::Core::Engine.routes.prepend do match '/admin/reports/bulk_coop' => 'admin/reports#bulk_coop', :as => "bulk_coop_admin_reports", :via => [:get, :post] match '/admin/reports/payments' => 'admin/reports#payments', :as => "payments_admin_reports", :via => [:get, :post] match '/admin/reports/order_cycles' => 'admin/reports#order_cycles', :as => "order_cycles_admin_reports", :via => [:get, :post] + + resources :orders do + get :select_distributor, :on => :member + get :deselect_distributor, :on => :collection + end end