Files
openfoodnetwork/app/controllers/enterprises_controller.rb
Rohan Mitchell 6d84cf7613 Merge branch 'master' into enterprises
Conflicts:
	app/controllers/enterprises_controller.rb
	app/views/spree/checkout/_distributor.html.haml
	db/schema.rb
	spec/lib/open_food_web/group_buy_report_spec.rb
2012-11-01 11:02:02 +11:00

54 lines
1.2 KiB
Ruby

class EnterprisesController < BaseController
def index
@enterprises = Enterprise.all
end
def suppliers
@suppliers = Enterprise.is_supplier
end
def distributors
@distributors = Enterprise.is_distributor
respond_to do |format|
format.js do
@distributor_details = Hash[@distributors.map { |d| [d.id, render_to_string(:partial => 'enterprises/distributor_details', :locals => {:distributor => d})] }]
end
end
end
def show
options = {:enterprise_id => params[:id]}
options.merge(params.reject { |k,v| k == :id })
@enterprise = Enterprise.find params[:id]
@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