Displaying setup instructions on Standing Orders index

This commit is contained in:
Rob Harrington
2017-01-18 15:17:48 +11:00
parent ae209f72b9
commit 57653cb911
7 changed files with 177 additions and 9 deletions

View File

@@ -0,0 +1,15 @@
@import '../plugins/font-awesome';
.todolist{
.todo {
&.done {
.title, .steps {
text-decoration: line-through;
}
i {
@extend .icon-check
}
}
}
}

View File

@@ -11,9 +11,14 @@ module Admin
def index
respond_to do |format|
format.html do
@order_cycles = OrderCycle.joins(:schedules).managed_by(spree_current_user)
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user)
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user)
if view_context.standing_orders_setup_complete?(@shops)
@order_cycles = OrderCycle.joins(:schedules).managed_by(spree_current_user)
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user)
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user)
else
@shop = @shops.first
render :setup_explanation
end
end
format.json { render_as_json @collection, ams_prefix: params[:ams_prefix] }
end

View File

@@ -0,0 +1,21 @@
module Admin
module StandingOrdersHelper
def standing_orders_setup_complete?(shops)
return false unless shops.any?
shops = shops.select{ |shop| shipping_and_payment_methods_ok?(shop) && customers_ok?(shop) }
Schedule.joins(:order_cycles).where(order_cycles: { coordinator_id: shops}).any?
end
def shipping_and_payment_methods_ok?(shop)
shop.present? && shop.shipping_methods.any? && shop.payment_methods.any?
end
def customers_ok?(shop)
shop.present? && shop.customers.any?
end
def schedules_ok?(shop)
shop.present? && Schedule.with_coordinator(shop).any?
end
end
end

View File

@@ -0,0 +1,51 @@
%h1.text-center.margin-bottom-30= t('admin.standing_order.standing_orders')
.row
.four.columns.alpha  
.twelve.columns.omega.todolist
%h4.margin-bottom-30= t('.just_a_few_more_steps')
.row.margin-bottom-20.todo{ class: @shop.present? ? 'done' : '' }
.one.columns.alpha
%i.text-big.icon-check-empty
.nine.columns.omega
.title.text-normal
%strong= t('.enable_standing_orders')
.steps
%div
= t('.enable_standing_orders_step_1_html',
enterprises_link: link_to(t('admin.enterprises.title'), main_app.admin_enterprises_path, target: '_blank'))
%div= t('.enable_standing_orders_step_2')
.row.margin-bottom-20.todo{ class: shipping_and_payment_methods_ok?(@shop) ? 'done' : '' }
.one.columns.alpha
%i.text-big.icon-check-empty
.nine.columns.omega
.title.text-normal
%strong
= t('.set_up_shipping_and_payment_methods_html',
shipping_link: link_to(t('admin.shipping'), admin_shipping_methods_path, target: '_blank'),
payment_link: link_to(t('admin.payment'), admin_payment_methods_path, target: '_blank'))
.row.margin-bottom-20.todo{ class: customers_ok?(@shop) ? 'done' : '' }
.one.columns.alpha
%i.text-big.icon-check-empty
.nine.columns.omega
.title.text-normal
%strong
= t('.ensure_at_least_one_customer_html',
customer_link: link_to(t('admin.customer'), main_app.admin_customers_path, target: '_blank'))
.row.margin-bottom-20.todo{ class: schedules_ok?(@shop) ? 'done' : '' }
.one.columns.alpha
%i.text-big.icon-check-empty
.nine.columns.omega
.title.text-normal
%strong= t('.create_at_least_one_schedule')
.steps
%div
= t('.create_at_least_one_schedule_step_1_html',
order_cycles_link: link_to("Order Cycles", main_app.admin_order_cycles_path, target: '_blank'))
%div= t('.create_at_least_one_schedule_step_2')
%div= t('.create_at_least_one_schedule_step_3')
.text-normal
= t('.once_you_are_done_you_can_html',
reload_this_page_link: link_to(t('.reload_this_page'), main_app.admin_standing_orders_path))

View File

@@ -203,6 +203,7 @@ en:
on_demand: On Demand
on_demand?: On Demand?
order_cycle: Order Cycle
payment: Payment
payment_method: Payment Method
phone: Phone
price: Price
@@ -210,6 +211,7 @@ en:
product: Product
quantity: Quantity
schedule: Schedule
shipping: Shipping
shipping_method: Shipping Method
shop: Shop
sku: SKU
@@ -809,6 +811,19 @@ en:
pause_standing_order: Pause Standing Order
unpause_standing_order: Unpause Standing Order
cancel_standing_order: Cancel Standing Order
setup_explanation:
just_a_few_more_steps: 'Just a few more steps before you can begin:'
enable_standing_orders: "Enable standing orders for at least one of your shops"
enable_standing_orders_step_1_html: 1. Go to the %{enterprises_link} page, find your shop, and click "Manage"
enable_standing_orders_step_2: 2. Under "Shop Preferences", enable the Standing Orders option
set_up_shipping_and_payment_methods_html: Set up %{shipping_link} and %{payment_link} methods
ensure_at_least_one_customer_html: Ensure that at least one %{customer_link} exists
create_at_least_one_schedule: Create at least one Schedule
create_at_least_one_schedule_step_1_html: 1. Go to the on the %{order_cycles_link} page
create_at_least_one_schedule_step_2: 2. Create an order cycle if you have not already done so
create_at_least_one_schedule_step_3: 3. Click '+ New Schedule', and fill out the form
once_you_are_done_you_can_html: Once you are done, you can %{reload_this_page_link}
reload_this_page: reload this page
steps:
details: 1. Basic Details
address: 2. Address

View File

@@ -6,7 +6,6 @@ describe Admin::StandingOrdersController, type: :controller do
describe 'index' do
let!(:user) { create(:user, enterprise_limit: 10) }
let!(:shop) { create(:distributor_enterprise, enable_standing_orders: true) }
let!(:standing_order) { create(:standing_order, shop: shop) }
before do
allow(controller).to receive(:spree_current_user) { user }
@@ -26,17 +25,31 @@ describe Admin::StandingOrdersController, type: :controller do
before { shop.update_attributes(owner: user) }
let!(:not_enabled_shop) { create(:distributor_enterprise, owner: user) }
it 'renders the index page with appropriate data' do
spree_get :index, params
expect(response).to render_template 'index'
expect(assigns(:collection)).to eq [] # No collection loaded
expect(assigns(:shops)).to eq [shop] # Shops are loaded
context "where I manage a shop that is set up for standing orders" do
let!(:standing_order) { create(:standing_order, shop: shop) }
it 'renders the index page with appropriate data' do
spree_get :index, params
expect(response).to render_template 'index'
expect(assigns(:collection)).to eq [] # No collection loaded
expect(assigns(:shops)).to eq [shop] # Shops are loaded
end
end
context "where I don't manage a shop that is set up for standing orders" do
it 'renders the setup_explanation page' do
spree_get :index, params
expect(response).to render_template 'setup_explanation'
expect(assigns(:collection)).to eq [] # No collection loaded
expect(assigns(:shop)).to eq shop # First SO enabled shop is loaded
end
end
end
end
context 'json' do
let(:params) { { format: :json } }
let!(:standing_order) { create(:standing_order, shop: shop) }
context 'as a regular user' do
it 'redirects to unauthorized' do

View File

@@ -0,0 +1,48 @@
require 'spec_helper'
describe Admin::StandingOrdersHelper, type: :helper do
describe "checking if setup is complete for any [shop]" do
let(:shop) { create(:distributor_enterprise) }
let(:customer) { create(:customer, enterprise: shop) }
let(:shipping_method) { create(:shipping_method, distributors: [shop]) }
let(:payment_method) { create(:payment_method, distributors: [shop]) }
let(:schedule) { create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: shop)] ) }
context "when a shop has no shipping methods present" do
before { customer; payment_method; schedule }
it { expect(helper.standing_orders_setup_complete?([shop])).to be false }
end
context "when a shop has no payment methods present" do
before { customer; shipping_method; schedule }
it { expect(helper.standing_orders_setup_complete?([shop])).to be false }
end
context "when a shop has no customers present" do
before { shipping_method; payment_method; schedule }
it { expect(helper.standing_orders_setup_complete?([shop])).to be false }
end
context "when a shop does not coordinate any schedules" do
before { customer; shipping_method; payment_method; }
it { expect(helper.standing_orders_setup_complete?([shop])).to be false }
end
context "when a shop meets all requirements" do
before { customer; shipping_method; payment_method; schedule }
let(:some_other_shop) { create(:distributor_enterprise) }
context "but it is not passed in" do
it { expect(helper.standing_orders_setup_complete?([some_other_shop])).to be false }
end
context "and it is passed in" do
it { expect(helper.standing_orders_setup_complete?([shop])).to be true }
end
context "and it is passed in with other shops that do not meet the requirements" do
it { expect(helper.standing_orders_setup_complete?([shop, some_other_shop])).to be true }
end
end
end
end