Skip to content

Commit

Permalink
Rearrange shipping method edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
oeoeaio committed Jun 18, 2014
1 parent 8412d74 commit 004548a
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Spree
module Admin
ShippingMethodsController.class_eval do
before_filter :do_not_destroy_referenced_shipping_methods, :only => :destroy
before_filter :load_hubs, only: [:new, :edit]
before_filter :load_hubs, only: [:new, :edit, :create, :update]

# Sort shipping methods by distributor name
# ! Code copied from Spree::Admin::ResourceController with two added lines
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/shipping_method_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Spree::ShippingMethod.class_eval do
has_and_belongs_to_many :distributors, join_table: 'distributors_shipping_methods', :class_name => 'Enterprise', association_foreign_key: 'distributor_id'
attr_accessible :distributor_ids
attr_accessible :distributor_ids, :description
attr_accessible :require_ship_address

scope :managed_by, lambda { |user|
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
remove "div[data-hook='admin_shipping_method_form_availability_fields']"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
remove "div[data-hook='admin_shipping_method_form_calculator_fields']"
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/ replace "div[data-hook='admin_shipping_method_form_fields']"
.alpha.twelve.columns{"data-hook" => "admin_shipping_method_form_fields"}
.row
.alpha.three.columns
= f.label :name, t(:name)
.omega.eight.columns
= f.text_field :name, :class => 'fullwidth', placeholder: "eg. 'Pick-up from Primary School'"
= error_message_on :shipping_method, :name
.row
.alpha.three.columns
= f.label :description, t(:description)
.omega.eight.columns
= f.text_area :description, class: 'fullwidth', rows: 2, placeholder: "eg. 'Please collect your order from 123 Imaginary St, Northcote, 3070'"
= error_message_on :shipping_method, :description
- if @available_zones.length == 1
= f.hidden_field :zone_id, value: @available_zones.first.id
- else
.row
.alpha.three.columns
= f.label :zone_id, t(:zone)
.omega.eight.columns
= f.collection_select(:zone_id, @available_zones, :id, :name, {}, {:class => 'select2 fullwidth'})
= error_message_on :shipping_method, :zone_id
- if spree_current_user.admin?
.row
.alpha.three.columns
= f.label :display_on, t(:display)
.omega.eight.columns
= select(:shipping_method, :display_on, Spree::ShippingMethod::DISPLAY.collect { |display| [t(display), display == :both ? nil : display.to_s] }, {}, {:class => 'select2 fullwidth'})
= error_message_on :shipping_method, :display_on
.row
-# Shipping Category used to be a select field, but we cut it down to two options to simplify the interface and because we thought 'Collection' and
-# 'Delivery' pretty much covered it. If we need more categories in the future, suggest reimplementing the select box from spree's code.
.three.columns.alpha
%label Category
= f.hidden_field :shipping_category_id, value: nil
- Spree::ShippingCategory.where(name: ['Delivery', 'Collection']).limit(2).each do |shipping_category|
.two.columns
= f.radio_button :shipping_category_id, shipping_category.id
 
= f.label "shipping_category_id_#{shipping_category.id}", t(shipping_category.name)
.row
.alpha.three.columns
= f.label :require_ship_address, "Requires shipping address?"
.two.columns
= f.radio_button :require_ship_address, true
 
= f.label :yes, t(:yes)
.six.columns
= f.radio_button :require_ship_address, false
 
= f.label :no, t(:no)

.row
.alpha.eleven.columns
= render :partial => 'spree/admin/shared/calculator_fields', :locals => { :f => f }
2 changes: 1 addition & 1 deletion app/views/spree/admin/shared/_hubs_sidebar.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- hubs_color = @hubs.count > 0 ? "blue" : "red"
.sidebar_item.four.columns#hubs
.sidebar_item.omega.four.columns#hubs
.four.columns.alpha.header{ class: "#{hubs_color}" }
%span.four.columns.alpha.centered Distributors
.four.columns.alpha.list{ class: "#{hubs_color}" }
Expand Down
32 changes: 22 additions & 10 deletions spec/features/admin/shipping_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@
# Given some distributors
d1 = create(:distributor_enterprise, name: 'Aeronautical Adventures')
d2 = create(:distributor_enterprise, name: 'Nautical Travels')
sc1 = create(:shipping_category, name: 'Delivery')
sc2 = create(:shipping_category, name: 'Collection')

# When I create a shipping method and set the distributors
# Shows appropriate fields when logged in as admin
visit spree.new_admin_shipping_method_path
page.should have_field 'shipping_method_name'
page.should have_field 'shipping_method_description'
page.should have_select 'shipping_method_display_on'
page.should have_field "shipping_method_shipping_category_id_#{sc1.id}"
page.should have_field "shipping_method_shipping_category_id_#{sc2.id}"
page.should have_field 'shipping_method_require_ship_address_true', checked: true

# When I create a shipping method and set the distributors
fill_in 'shipping_method_name', with: 'Carrier Pidgeon'
check "shipping_method_distributor_ids_#{d1.id}"
check "shipping_method_distributor_ids_#{d2.id}"
Expand Down Expand Up @@ -70,19 +80,21 @@
login_to_admin_as enterprise_user
end

it "lets me choose whether a shipping address is required" do
click_link "Enterprises"
within(".enterprise-#{distributor1.id}") { click_link 'Shipping Methods' }
click_link 'New Shipping Method'

page.should have_content "Requires shipping address?"
end

it "creates shipping methods" do
it "creating a shipping method" do
sc1 = create(:shipping_category, name: 'Delivery')
sc2 = create(:shipping_category, name: 'Collection')
click_link 'Enterprises'
within(".enterprise-#{distributor1.id}") { click_link 'Shipping Methods' }
click_link 'New Shipping Method'

# Show the correct fields
page.should have_field 'shipping_method_name'
page.should have_field 'shipping_method_description'
page.should_not have_select 'shipping_method_display_on'
page.should have_field "shipping_method_shipping_category_id_#{sc1.id}"
page.should have_field "shipping_method_shipping_category_id_#{sc2.id}"
page.should have_field 'shipping_method_require_ship_address_true', checked: true

fill_in 'shipping_method_name', :with => 'Teleport'

check "shipping_method_distributor_ids_#{distributor1.id}"
Expand Down

0 comments on commit 004548a

Please sign in to comment.