Skip to content

Commit

Permalink
Add OptionTypesController with position update and destroy actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rainerdema committed Nov 29, 2023
1 parent dba880d commit c06be73
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
31 changes: 31 additions & 0 deletions admin/app/controllers/solidus_admin/option_types_controller.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions admin/config/locales/option_types.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
en:
solidus_admin:
option_types:
title: "Option Types"
destroy:
success: "Option Types were successfully removed."
9 changes: 9 additions & 0 deletions admin/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@
delete :destroy
end
end

resources :option_types do
collection do
delete :destroy
end
member do
patch :move
end
end
end

0 comments on commit c06be73

Please sign in to comment.