diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d95e6d55b2..8d99d43af0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -29,7 +29,7 @@ class ApplicationController < ActionController::Base end def require_distributor_chosen - unless current_order(false).andand.distributor + unless current_distributor redirect_to spree.root_path false end diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index a1717a3d2c..ba53ff4a0f 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -1,6 +1,7 @@ class BaseController < ApplicationController include Spree::Core::ControllerHelpers include Spree::Core::ControllerHelpers::RespondWith + include EnterprisesHelper include OrderCyclesHelper helper 'spree/base' diff --git a/app/controllers/spree/products_controller_decorator.rb b/app/controllers/spree/products_controller_decorator.rb index 99fefc4fbb..fbb5c0532b 100644 --- a/app/controllers/spree/products_controller_decorator.rb +++ b/app/controllers/spree/products_controller_decorator.rb @@ -3,15 +3,11 @@ require 'open_food_network/split_products_by_distribution' Spree::ProductsController.class_eval do include EnterprisesHelper include OrderCyclesHelper - include OpenFoodNetwork::SplitProductsByDistribution before_filter :require_distributor_chosen, only: :index respond_override :index => { :html => { :success => lambda { - if current_order_cycle - order_cycle_products = current_order_cycle.products - @products.select! { |p| order_cycle_products.include? p } - end + redirect_to main_app.enterprise_path(current_distributor) } } } end diff --git a/spec/controllers/spree/products_controller_spec.rb b/spec/controllers/spree/products_controller_spec.rb index 078f9805c4..b0d88e0b70 100644 --- a/spec/controllers/spree/products_controller_spec.rb +++ b/spec/controllers/spree/products_controller_spec.rb @@ -7,4 +7,14 @@ describe Spree::ProductsController do response.should redirect_to spree.root_path end end + + context "when a distributor has been chosen" do + it "redirects #index to the distributor page" do + d = create(:distributor_enterprise) + controller.stub(:current_distributor) { d } + + spree_get :index + response.should redirect_to enterprise_path(d) + end + end end