Files
openfoodnetwork/app/controllers/base_controller.rb
Cillian O'Ruanaidh 747c88fb35 Update the Shop::OrderCyclesList service so it's clearer what kind of order cycles are being fetched
Before the Shop::OrderCyclesList service would return order cycles even if they are not ready for checkout and we had a check before calling the service in BaseController which would return OrderCycle.where('false'). It seems like this check should be part of the service too.
2022-09-30 13:13:39 +01:00

35 lines
885 B
Ruby

# frozen_string_literal: true
require 'spree/core/controller_helpers/order'
require 'open_food_network/tag_rule_applicator'
class BaseController < ApplicationController
layout 'darkswarm'
include Spree::Core::ControllerHelpers::Order
include I18nHelper
include OrderCyclesHelper
before_action :set_locale
private
def set_order_cycles
@order_cycles = Shop::OrderCyclesList.ready_for_checkout_for(@distributor, current_customer)
set_order_cycle
end
# Default to the only order cycle if there's only one
#
# Here we need to use @order_cycles.size not @order_cycles.count
# because OrderCyclesList returns a modified ActiveRecord::Relation
# and these modifications are not seen if it is reloaded with count
def set_order_cycle
return if @order_cycles.size != 1
current_order(true).set_order_cycle! @order_cycles.first
end
end