diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 2ac35fa3ad..1d74df5706 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -11,8 +11,19 @@ class BaseController < ApplicationController include Spree::ProductsHelper before_filter :check_order_cycle_expiry - + def load_active_distributors @active_distributors ||= Enterprise.distributors_with_active_order_cycles end + + private + + def set_order_cycles + @order_cycles = OrderCycle.with_distributor(@distributor).active + + # And default to the only order cycle if there's only the one + if @order_cycles.count == 1 + current_order(true).set_order_cycle! @order_cycles.first + end + end end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index d8b33e4ad6..77cebdb183 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -92,13 +92,4 @@ class EnterprisesController < BaseController def clean_permalink params[:permalink] = params[:permalink].parameterize end - - def set_order_cycles - @order_cycles = OrderCycle.with_distributor(@distributor).active - - # And default to the only order cycle if there's only the one - if @order_cycles.count == 1 - current_order(true).set_order_cycle! @order_cycles.first - end - end end diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index c350791158..73861def5c 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -3,6 +3,7 @@ require 'open_food_network/scope_product_to_hub' class ShopController < BaseController layout "darkswarm" before_filter :require_distributor_chosen + before_filter :set_order_cycles def show redirect_to main_app.enterprise_shop_path(current_distributor)