mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Split product distribution editing into its own admin page
This commit is contained in:
@@ -7,6 +7,9 @@ Spree::Admin::ProductsController.class_eval do
|
||||
|
||||
#respond_override :clone => { :json => {:success => lambda { redirect_to bulk_index_admin_products_url+"?q[id_eq]=#{@new.id}" } } }
|
||||
|
||||
def product_distributions
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
collection_hash = Hash[params[:_json].each_with_index.map { |p,i| [i,p] }]
|
||||
product_set = Spree::ProductSet.new({:collection_attributes => collection_hash})
|
||||
|
||||
@@ -10,7 +10,7 @@ class AbilityDecorator
|
||||
|
||||
# Enterprise User can only access products that they are a supplier for
|
||||
can [:create], Spree::Product
|
||||
can [:admin, :read, :update, :bulk_edit, :bulk_update, :clone, :destroy], Spree::Product do |product|
|
||||
can [:admin, :read, :update, :product_distributions, :bulk_edit, :bulk_update, :clone, :destroy], Spree::Product do |product|
|
||||
user.enterprises.include? product.supplier
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
|
||||
:insert_bottom => "[data-hook='admin_product_form_additional_fields']",
|
||||
:partial => "spree/admin/products/distributors_form",
|
||||
:name => "add_distributor_to_admin_product_edit",
|
||||
:original => '5a6c66358efbce3e73eb60a168ac4914a6bcc27f')
|
||||
@@ -1,5 +0,0 @@
|
||||
Deface::Override.new(:virtual_path => "spree/admin/products/new",
|
||||
:insert_after => "[data-hook='new_product_attrs']",
|
||||
:partial => "spree/admin/products/distributors_form",
|
||||
:name => "add_distributor_to_admin_product_new",
|
||||
:original => '59b7ed369769267bdedb596768fcfcc2cb94f122')
|
||||
@@ -0,0 +1,5 @@
|
||||
/ insert_bottom "[data-hook='admin_product_tabs']"
|
||||
|
||||
- klass = current == 'Product Distributions' ? 'active' : ''
|
||||
%li{:class => klass}
|
||||
= link_to_with_icon 'icon-tasks', 'Product Distributions', product_distributions_admin_product_url(@product)
|
||||
@@ -0,0 +1,8 @@
|
||||
= render :partial => 'spree/admin/shared/product_sub_menu'
|
||||
= render :partial => 'spree/admin/shared/product_tabs', :locals => { :current => 'Product Distributions' }
|
||||
= render :partial => 'spree/shared/error_messages', :locals => { :target => @product }
|
||||
|
||||
= form_for [:admin, @product], :method => :put, :html => { :multipart => true } do |f|
|
||||
%fieldset.no-border-top
|
||||
= render :partial => 'distributors_form', :locals => { :f => f }
|
||||
= render :partial => 'spree/admin/shared/edit_resource_links'
|
||||
@@ -75,6 +75,8 @@ Spree::Core::Engine.routes.prepend do
|
||||
|
||||
namespace :admin do
|
||||
resources :products do
|
||||
get :product_distributions, on: :member
|
||||
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,19 +24,26 @@ feature %q{
|
||||
fill_in 'product_price', :with => '19.99'
|
||||
select 'New supplier', :from => 'product_supplier_id'
|
||||
|
||||
check @distributors[0].name
|
||||
select @enterprise_fees[0].name, :from => 'product_product_distributions_attributes_0_enterprise_fee_id'
|
||||
check @distributors[2].name
|
||||
select @enterprise_fees[2].name, :from => 'product_product_distributions_attributes_2_enterprise_fee_id'
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.supplier.should == @supplier
|
||||
product.group_buy.should be_false
|
||||
|
||||
# Distributors
|
||||
within('#sidebar') { click_link 'Product Distributions' }
|
||||
|
||||
check @distributors[0].name
|
||||
select @enterprise_fees[0].name, :from => 'product_product_distributions_attributes_0_enterprise_fee_id'
|
||||
check @distributors[2].name
|
||||
select @enterprise_fees[2].name, :from => 'product_product_distributions_attributes_2_enterprise_fee_id'
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
product.reload
|
||||
product.distributors.should == [@distributors[0], @distributors[2]]
|
||||
product.product_distributions.map { |pd| pd.enterprise_fee }.should == [@enterprise_fees[0], @enterprise_fees[2]]
|
||||
product.group_buy.should be_false
|
||||
end
|
||||
|
||||
scenario "making a group buy product" do
|
||||
@@ -86,6 +93,20 @@ feature %q{
|
||||
page.should_not have_content @supplier.name
|
||||
end
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.supplier.should == @supplier2
|
||||
end
|
||||
|
||||
scenario "editing product distributions" do
|
||||
product = create(:simple_product, supplier: @supplier2)
|
||||
|
||||
click_link 'Products'
|
||||
click_link product.name
|
||||
within('#sidebar') { click_link 'Product Distributions' }
|
||||
|
||||
check @distributors[0].name
|
||||
select @enterprise_fees[0].name, :from => 'product_product_distributions_attributes_0_enterprise_fee_id'
|
||||
|
||||
@@ -95,14 +116,11 @@ feature %q{
|
||||
page.should_not have_content @distributors[2].name
|
||||
end
|
||||
|
||||
click_button 'Create'
|
||||
click_button 'Update'
|
||||
flash_message.should == "Product \"#{product.name}\" has been successfully updated!"
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.supplier.should == @supplier2
|
||||
product.distributors.should == [@distributors[0]]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,11 +32,11 @@ module Spree
|
||||
let(:order) {create(:order)}
|
||||
|
||||
it "should be able to read/write their enterprises' products" do
|
||||
should have_ability([:admin, :read, :update, :bulk_edit, :bulk_update, :clone, :destroy], for: p1)
|
||||
should have_ability([:admin, :read, :update, :product_distributions, :bulk_edit, :bulk_update, :clone, :destroy], for: p1)
|
||||
end
|
||||
|
||||
it "should not be able to read/write other enterprises' products" do
|
||||
should_not have_ability([:admin, :read, :update, :bulk_edit, :bulk_update, :clone, :destroy], for: p2)
|
||||
should_not have_ability([:admin, :read, :update, :product_distributions, :bulk_edit, :bulk_update, :clone, :destroy], for: p2)
|
||||
end
|
||||
|
||||
it "should be able to create a new product" do
|
||||
|
||||
Reference in New Issue
Block a user