From a3243adaf7f1b2b3fac683da26eea4d9c55298c5 Mon Sep 17 00:00:00 2001 From: Rainer Dema Date: Wed, 29 Nov 2023 17:29:37 +0100 Subject: [PATCH] Add OptionTypesController with position update and destroy actions --- .../solidus_admin/option_types_controller.rb | 31 +++++++++++++++++++ admin/config/locales/option_types.en.yml | 6 ++++ admin/config/routes.rb | 9 ++++++ 3 files changed, 46 insertions(+) create mode 100644 admin/app/controllers/solidus_admin/option_types_controller.rb create mode 100644 admin/config/locales/option_types.en.yml diff --git a/admin/app/controllers/solidus_admin/option_types_controller.rb b/admin/app/controllers/solidus_admin/option_types_controller.rb new file mode 100644 index 00000000000..6354b0ebf72 --- /dev/null +++ b/admin/app/controllers/solidus_admin/option_types_controller.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module SolidusAdmin + class OptionTypesController < SolidusAdmin::BaseController + before_action :load_option_type, only: [:move] + + def move + @option_type.insert_at(params[:position].to_i) + + respond_to do |format| + format.js { head :no_content } + end + end + + def destroy + @option_types = Spree::OptionType.where(id: params[:id]) + + Spree::OptionType.transaction { @option_types.destroy_all } + + flash[:notice] = t('.success') + redirect_back_or_to option_types_path, status: :see_other + end + + private + + def load_option_type + @option_type = Spree::OptionType.find(params[:id]) + authorize! action_name, @option_type + end + end +end diff --git a/admin/config/locales/option_types.en.yml b/admin/config/locales/option_types.en.yml new file mode 100644 index 00000000000..fb439e8d07b --- /dev/null +++ b/admin/config/locales/option_types.en.yml @@ -0,0 +1,6 @@ +en: + solidus_admin: + option_types: + title: "Option Types" + destroy: + success: "Option Types were successfully removed." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index eeb32c0884e..a369a1b4b42 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -42,4 +42,13 @@ delete :destroy end end + + resources :option_types do + collection do + delete :destroy + end + member do + patch :move + end + end end