mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Move select_distributor and deselect_distributor actions from enterprises controller to orders controller
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user