mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Instead of parsing URLs pass order through method for Orders Ctrl
Use methods for before_actions Maybe we should for hide_of_navigation too, but a name 'hide_ofn_navigation_for_order_distributor' seemed unhelpful..
This commit is contained in:
committed by
David Cook
parent
4fa44e6c64
commit
dd9fec58a4
@@ -4,21 +4,11 @@ module WhiteLabel
|
||||
extend ActiveSupport::Concern
|
||||
include EnterprisesHelper
|
||||
|
||||
def hide_ofn_navigation
|
||||
def hide_ofn_navigation(distributor = current_distributor)
|
||||
return false unless OpenFoodNetwork::FeatureToggle.enabled?(:white_label)
|
||||
|
||||
# if the distributor has the hide_ofn_navigation preference set to true
|
||||
# then we should hide the OFN navigation
|
||||
@hide_ofn_navigation = distributor.preferred_hide_ofn_navigation
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def distributor
|
||||
return current_distributor unless request.path.start_with?("/orders/")
|
||||
|
||||
# if we are on an order confirmation page,
|
||||
# we need to get the distributor from the order, not the current one
|
||||
Spree::Order.find_by(number: params[:id]).distributor
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,8 @@ module Spree
|
||||
respond_to :html, :json
|
||||
|
||||
before_action :check_authorization
|
||||
before_action :set_current_order, only: :update
|
||||
before_action :set_order_from_params, only: :show
|
||||
before_action :set_current_order, only: [:edit, :update]
|
||||
before_action :filter_order_params, only: :update
|
||||
|
||||
prepend_before_action :require_order_authentication, only: :show
|
||||
@@ -23,12 +24,13 @@ module Spree
|
||||
prepend_before_action :require_distributor_chosen, only: :edit
|
||||
before_action :check_hub_ready_for_checkout, only: :edit
|
||||
before_action :check_at_least_one_line_item, only: :update
|
||||
before_action :hide_ofn_navigation, only: [:show, :edit]
|
||||
|
||||
def show
|
||||
@order = Spree::Order.find_by!(number: params[:id])
|
||||
before_action only: [:show, :edit] do
|
||||
hide_ofn_navigation(@order.distributor)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def empty
|
||||
if @order = current_order
|
||||
@order.empty!
|
||||
@@ -39,7 +41,6 @@ module Spree
|
||||
|
||||
# Patching to redirect to shop if order is empty
|
||||
def edit
|
||||
@order = current_order(true)
|
||||
@insufficient_stock_lines = @order.insufficient_stock_lines
|
||||
@unavailable_order_variants = OrderCycleDistributedVariants.
|
||||
new(current_order_cycle, current_distributor).unavailable_order_variants(@order)
|
||||
@@ -108,6 +109,10 @@ module Spree
|
||||
|
||||
private
|
||||
|
||||
def set_order_from_params
|
||||
@order = Spree::Order.find_by!(number: params[:id])
|
||||
end
|
||||
|
||||
def set_current_order
|
||||
@order = current_order(true)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user