From c06be73e48605155163bc9c58f58452edc9863bb 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 9cd0b6d6822..a3caed47d42 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -48,4 +48,13 @@ delete :destroy end end + + resources :option_types do + collection do + delete :destroy + end + member do + patch :move + end + end end