From 39889390ef9bc753441a854677fca59703b9e8c8 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 16 Jan 2015 12:35:58 +1100 Subject: [PATCH] Altering shop page routing so that shop url is copy-and-pastable --- app/controllers/enterprises_controller.rb | 16 ++++++++++++++-- app/controllers/shop_controller.rb | 12 +----------- .../shop.html.haml} | 0 config/routes.rb | 1 + 4 files changed, 16 insertions(+), 13 deletions(-) rename app/views/{shop/show.html.haml => enterprises/shop.html.haml} (100%) diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 27a335d9c4..4414dd4ece 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -1,6 +1,9 @@ class EnterprisesController < BaseController + layout "darkswarm" helper Spree::ProductsHelper include OrderCyclesHelper + before_filter :set_order_cycles, only: :shop + before_filter :load_active_distributors, only: :shop def index @enterprises = Enterprise.all @@ -66,8 +69,6 @@ class EnterprisesController < BaseController order_cycle_options = OrderCycle.active.with_distributor(distributor) order.order_cycle = order_cycle_options.first if order_cycle_options.count == 1 order.save! - - redirect_to main_app.shop_path end def check_permalink @@ -82,4 +83,15 @@ class EnterprisesController < BaseController end end 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/shop_controller.rb b/app/controllers/shop_controller.rb index c0c2c225a5..c350791158 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -3,10 +3,9 @@ require 'open_food_network/scope_product_to_hub' class ShopController < BaseController layout "darkswarm" before_filter :require_distributor_chosen - before_filter :set_order_cycles - before_filter :load_active_distributors def show + redirect_to main_app.enterprise_shop_path(current_distributor) end def products @@ -36,15 +35,6 @@ class ShopController < BaseController 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 - def products_for_shop if current_order_cycle current_order_cycle. diff --git a/app/views/shop/show.html.haml b/app/views/enterprises/shop.html.haml similarity index 100% rename from app/views/shop/show.html.haml rename to app/views/enterprises/shop.html.haml diff --git a/config/routes.rb b/config/routes.rb index 912741322e..0d5d034df4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -34,6 +34,7 @@ Openfoodnetwork::Application.routes.draw do get :shop # old world end end + get '/:id/shop', to: 'enterprises#shop', as: 'enterprise_shop' devise_for :enterprise, controllers: { confirmations: 'enterprise_confirmations' }