Files
openfoodnetwork/app/controllers/base_controller.rb
2016-05-27 16:25:10 +10:00

35 lines
1010 B
Ruby

class BaseController < ApplicationController
include Spree::Core::ControllerHelpers
include Spree::Core::ControllerHelpers::RespondWith
include EnterprisesHelper
include OrderCyclesHelper
helper 'spree/base'
# Spree::Core::ControllerHelpers declares helper_method get_taxonomies, so we need to
# include Spree::ProductsHelper so that method is available on the controller
include Spree::ProductsHelper
before_filter :check_order_cycle_expiry
private
def set_order_cycles
@order_cycles = OrderCycle.with_distributor(@distributor).active
.order(@distributor.preferred_shopfront_order_cycle_order)
@distributor.apply_tag_rules(
type: "FilterOrderCycles",
subject: @order_cycles,
customer_tags: current_order.andand.customer.andand.tag_list || [],
shop: @distributor
)
# 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