mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Admin can assign multiple distributors to a shipping method
This commit is contained in:
@@ -4,7 +4,7 @@ module Spree
|
||||
before_filter :do_not_destroy_referenced_shipping_methods, :only => :destroy
|
||||
|
||||
# Sort shipping methods by distributor name
|
||||
# ! Redundant code copied from Spree::Admin::ResourceController with two added lines
|
||||
# ! Code copied from Spree::Admin::ResourceController with two added lines
|
||||
def collection
|
||||
return parent.send(controller_name) if parent_data.present?
|
||||
if model_class.respond_to?(:accessible_by) && !current_ability.has_block?(params[:action], model_class)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/ insert_bottom "[data-hook='admin_shipping_method_form_availability_fields'] > fieldset"
|
||||
|
||||
= f.field_container :shipping_category do
|
||||
= f.label :distributor_id, 'Distributor'
|
||||
= f.collection_select :distributor_id, Enterprise.is_distributor, :id, :name, {include_blank: false}, {class: 'select2 fullwidth'}
|
||||
= f.field_container :distributors do
|
||||
= f.label :distributor_ids, 'Distributors'
|
||||
- distributors = Enterprise.is_distributor.managed_by(spree_current_user) | f.object.distributors
|
||||
= f.collection_select(:distributor_ids, distributors, :id, :name, {include_blank: false}, {class: "select2 fullwidth", multiple: true})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/ insert_top "[data-hook='admin_shipping_methods_index_rows']"
|
||||
|
||||
%td.align-center
|
||||
= shipping_method.distributor.name
|
||||
= enterprises_to_names shipping_method.distributors
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/ insert_top "[data-hook='admin_shipping_methods_index_headers']"
|
||||
|
||||
%th
|
||||
Distributor
|
||||
Distributors
|
||||
|
||||
@@ -9,14 +9,16 @@ feature 'shipping methods' do
|
||||
@sm = create(:shipping_method)
|
||||
end
|
||||
|
||||
scenario "creating a shipping method owned by a distributor" do
|
||||
# Given a distributor
|
||||
distributor = create(:distributor_enterprise, name: 'Aeronautical Adventures')
|
||||
scenario "creating a shipping method owned by some distributors" do
|
||||
# Given some distributors
|
||||
d1 = create(:distributor_enterprise, name: 'Aeronautical Adventures')
|
||||
d2 = create(:distributor_enterprise, name: 'Nautical Travels')
|
||||
|
||||
# When I create a shipping method and set the distributor
|
||||
# When I create a shipping method and set the distributors
|
||||
visit spree.new_admin_shipping_method_path
|
||||
fill_in 'shipping_method_name', with: 'Carrier Pidgeon'
|
||||
select 'Aeronautical Adventures', from: 'shipping_method_distributor_id'
|
||||
select 'Aeronautical Adventures', from: 'shipping_method_distributor_ids'
|
||||
select 'Nautical Travels', from: 'shipping_method_distributor_ids'
|
||||
click_button 'Create'
|
||||
|
||||
# Then the shipping method should have its distributor set
|
||||
@@ -24,10 +26,9 @@ feature 'shipping methods' do
|
||||
|
||||
sm = Spree::ShippingMethod.last
|
||||
sm.name.should == 'Carrier Pidgeon'
|
||||
sm.distributor.should == distributor
|
||||
sm.distributors.should == [d1, d2]
|
||||
end
|
||||
|
||||
it "shipping method requires distributor"
|
||||
it "at checkout, user can only see shipping methods for their current distributor (checkout spec)"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user