mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Adding some requirement filters to the Orders controller
This commit is contained in:
@@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
|
||||
before_filter :load_data_for_sidebar
|
||||
before_filter :require_certified_hostname
|
||||
|
||||
include EnterprisesHelper
|
||||
|
||||
def after_sign_in_path_for(resource)
|
||||
if request.referer and referer_path = URI(request.referer).path
|
||||
@@ -44,6 +45,12 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
end
|
||||
|
||||
def require_order_cycle
|
||||
unless current_order_cycle
|
||||
redirect_to main_app.shop_path
|
||||
end
|
||||
end
|
||||
|
||||
def check_order_cycle_expiry
|
||||
if current_order_cycle.andand.closed?
|
||||
session[:expired_order_cycle_id] = current_order_cycle.id
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class Shop::CheckoutController < Spree::CheckoutController
|
||||
layout 'darkswarm'
|
||||
|
||||
prepend_before_filter :require_order_cycle
|
||||
prepend_before_filter :require_distributor_chosen
|
||||
skip_before_filter :check_registration
|
||||
@@ -62,12 +61,6 @@ class Shop::CheckoutController < Spree::CheckoutController
|
||||
redirect_to main_app.root_path
|
||||
end
|
||||
end
|
||||
|
||||
def require_order_cycle
|
||||
unless current_order_cycle
|
||||
redirect_to main_app.shop_path
|
||||
end
|
||||
end
|
||||
|
||||
def load_order
|
||||
@order = current_order
|
||||
|
||||
@@ -5,6 +5,9 @@ Spree::OrdersController.class_eval do
|
||||
before_filter :update_distribution, :only => :update
|
||||
before_filter :filter_order_params, :only => :update
|
||||
|
||||
prepend_before_filter :require_order_cycle, only: [:edit]
|
||||
prepend_before_filter :require_distributor_chosen, only: [:edit]
|
||||
|
||||
layout 'darkswarm'
|
||||
|
||||
# Patch Orders#populate to populate multi_cart (if enabled)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module ApplicationHelper
|
||||
include FoundationRailsHelper::FlashHelper
|
||||
|
||||
|
||||
def home_page_cms_content
|
||||
if controller.controller_name == 'home' && controller.action_name == 'index'
|
||||
cms_page_content(:content, Cms::Page.find_by_full_path('/'))
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::OrdersController do
|
||||
let(:distributor) { double(:distributor) }
|
||||
|
||||
it "redirects home when no distributor is selected" do
|
||||
spree_get :edit
|
||||
response.should redirect_to root_path
|
||||
end
|
||||
|
||||
it "redirects to the shop when no order cycle is selected" do
|
||||
controller.stub(:current_distributor).and_return(distributor)
|
||||
spree_get :edit
|
||||
response.should redirect_to shop_path
|
||||
end
|
||||
|
||||
it "selects distributors" do
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
Reference in New Issue
Block a user