diff --git a/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee b/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee new file mode 100644 index 0000000000..a2de809d8c --- /dev/null +++ b/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee @@ -0,0 +1,2 @@ +angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Enterprises) -> + $scope.Enterprises = Enterprises diff --git a/app/controllers/spree/admin/products_controller_decorator.rb b/app/controllers/spree/admin/products_controller_decorator.rb index 8561704686..25b25c6b8f 100644 --- a/app/controllers/spree/admin/products_controller_decorator.rb +++ b/app/controllers/spree/admin/products_controller_decorator.rb @@ -2,6 +2,7 @@ require 'open_food_network/spree_api_key_loader' Spree::Admin::ProductsController.class_eval do include OpenFoodNetwork::SpreeApiKeyLoader + include OrderCyclesHelper before_filter :load_form_data, :only => [:bulk_edit, :new, :create, :edit, :update] before_filter :load_spree_api_key, :only => :bulk_edit @@ -48,6 +49,12 @@ Spree::Admin::ProductsController.class_eval do end end + def override_variants + @all_enterprises = [] + @my_enterprises = order_cycle_permitted_enterprises.by_name + end + + protected def location_after_save if URI(request.referer).path == '/admin/products/bulk_edit' diff --git a/app/overrides/spree/admin/shared/_product_sub_menu/add_override_variants_tab.html.haml.deface b/app/overrides/spree/admin/shared/_product_sub_menu/add_override_variants_tab.html.haml.deface new file mode 100644 index 0000000000..5b4bb2983e --- /dev/null +++ b/app/overrides/spree/admin/shared/_product_sub_menu/add_override_variants_tab.html.haml.deface @@ -0,0 +1,3 @@ +/ insert_bottom "[data-hook='admin_product_sub_tabs']" + += tab :override_details, url: override_variants_admin_products_path, match_path: '/products/override_variants' diff --git a/app/views/spree/admin/products/override_variants.html.haml b/app/views/spree/admin/products/override_variants.html.haml new file mode 100644 index 0000000000..6f9ffafb31 --- /dev/null +++ b/app/views/spree/admin/products/override_variants.html.haml @@ -0,0 +1,5 @@ += render 'spree/admin/products/override_variants/header' += render 'spree/admin/products/override_variants/data' + +%div{ ng: { app: 'ofn.admin', controller: 'AdminOverrideVariantsCtrl', init: 'initialise()' } } + = render 'spree/admin/products/override_variants/hub_choice' diff --git a/app/views/spree/admin/products/override_variants/_data.html.haml b/app/views/spree/admin/products/override_variants/_data.html.haml new file mode 100644 index 0000000000..6ff3621ab4 --- /dev/null +++ b/app/views/spree/admin/products/override_variants/_data.html.haml @@ -0,0 +1 @@ += admin_inject_enterprises diff --git a/app/views/spree/admin/products/override_variants/_header.html.haml b/app/views/spree/admin/products/override_variants/_header.html.haml new file mode 100644 index 0000000000..7b4a38db47 --- /dev/null +++ b/app/views/spree/admin/products/override_variants/_header.html.haml @@ -0,0 +1,4 @@ +- content_for :page_title do + Override Product Details + += render :partial => 'spree/admin/shared/product_sub_menu' diff --git a/app/views/spree/admin/products/override_variants/_hub_choice.html.haml b/app/views/spree/admin/products/override_variants/_hub_choice.html.haml new file mode 100644 index 0000000000..a2519b7312 --- /dev/null +++ b/app/views/spree/admin/products/override_variants/_hub_choice.html.haml @@ -0,0 +1,7 @@ +.row + .two.columns.alpha + Hub + .four.columns + %select.select2.fullwidth#hub_id{ 'ng-model' => 'hub_id', name: 'hub_id', 'ng-options' => 'hub.id as hub.name for hub in Enterprises.my_enterprises' } + .ten.columns.omega + %input{ type: 'button', value: 'Go', 'ng-click' => 'selectHub()' } diff --git a/config/routes.rb b/config/routes.rb index a860ec8acf..75380a55f5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -118,6 +118,7 @@ Spree::Core::Engine.routes.prepend do match '/admin/reports/orders_and_fulfillment' => 'admin/reports#orders_and_fulfillment', :as => "orders_and_fulfillment_admin_reports", :via => [:get, :post] match '/admin/reports/users_and_enterprises' => 'admin/reports#users_and_enterprises', :as => "users_and_enterprises_admin_reports", :via => [:get, :post] match '/admin/products/bulk_edit' => 'admin/products#bulk_edit', :as => "bulk_edit_admin_products" + match '/admin/products/override_variants' => 'admin/products#override_variants', :as => "override_variants_admin_products" match '/admin/orders/bulk_management' => 'admin/orders#bulk_management', :as => "admin_bulk_order_management" match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post] match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post] diff --git a/spec/features/admin/override_variants_spec.rb b/spec/features/admin/override_variants_spec.rb new file mode 100644 index 0000000000..5df70b200b --- /dev/null +++ b/spec/features/admin/override_variants_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +feature %q{ + As an Administrator + With products I can add to order cycles + I want to override the stock level and price of those products + Without affecting other hubs that share the same products +}, js: true do + include AuthenticationWorkflow + include WebHelper + + before do + login_to_admin_section + end + + use_short_wait + + describe "selecting a hub" do + let!(:hub) { create(:distributor_enterprise) } + + it "displays a list of hub choices" do + visit '/admin/products/override_variants' + page.should have_select2 'hub_id', with_options: [hub.name] + end + end +end