Altering shop page routing so that shop url is copy-and-pastable

This commit is contained in:
Rob Harrington
2015-01-16 12:35:58 +11:00
parent c3659612ed
commit 39889390ef
4 changed files with 16 additions and 13 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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' }