Class: SolidusAdmin::StoreCreditsController
- Inherits:
-
ResourcesController
- Object
- ApplicationController
- BaseController
- ResourcesController
- SolidusAdmin::StoreCreditsController
- Defined in:
- app/controllers/solidus_admin/store_credits_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #edit_amount ⇒ Object
- #edit_memo ⇒ Object
- #edit_validity ⇒ Object
- #index ⇒ Object
- #invalidate ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update_amount ⇒ Object
- #update_memo ⇒ Object
Methods inherited from ResourcesController
Methods included from ComponentsHelper
Instance Method Details
#create ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 39 def create @store_credit = @user.store_credits.build( permitted_resource_params.merge({ created_by: spree_current_user, action_originator: spree_current_user }) ) return unless ensure_amount { render_new_with_errors } return unless ensure_store_credit_category { render_new_with_errors } if @store_credit.save flash[:notice] = t('.success') redirect_to after_create_path, status: :see_other else render_new_with_errors end end |
#edit_amount ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 58 def edit_amount respond_to do |format| format.html { render component("users/store_credits/edit_amount").new( user: @user, store_credit: @store_credit, reasons: @store_credit_reasons ) } end end |
#edit_memo ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 82 def edit_memo respond_to do |format| format.html { render component("users/store_credits/edit_memo").new( user: @user, store_credit: @store_credit, ) } end end |
#edit_validity ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 104 def edit_validity respond_to do |format| format.html { render component("users/store_credits/edit_validity").new( user: @user, store_credit: @store_credit, reasons: @store_credit_reasons ) } end end |
#index ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 11 def index @store_credits = Spree::StoreCredit.where(user_id: @user.id).order(id: :desc) respond_to do |format| format.html { render component("users/store_credits/index").new(user: @user, store_credits: @store_credits) } end end |
#invalidate ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 116 def invalidate return unless ensure_store_credit_reason { render_edit_with_errors } if @store_credit.invalidate(@store_credit_reason, spree_current_user) flash[:notice] = t('.success') else # Ensure store_credit_reason handles invalid param/form submissions and modal re-rendering. # This is just a fallback error state in case anything goes wrong with StoreCredit#invalidate. flash[:error] = t('.failure') end redirect_to after_update_path, status: :see_other end |
#new ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 25 def new @store_credit ||= Spree::StoreCredit.new respond_to do |format| format.html { render component("users/store_credits/new").new( user: @user, store_credit: @store_credit, categories: @store_credit_categories ) } end end |
#show ⇒ Object
19 20 21 22 23 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 19 def show respond_to do |format| format.html { render component("users/store_credits/show").new(user: @user, store_credit: @store_credit, events: @store_credit_events) } end end |
#update_amount ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 70 def update_amount return unless ensure_amount { render_edit_with_errors } return unless ensure_store_credit_reason { render_edit_with_errors } if @store_credit.update_amount(permitted_resource_params[:amount], @store_credit_reason, spree_current_user) flash[:notice] = t('.success') redirect_to after_update_path, status: :see_other else render_edit_with_errors end end |
#update_memo ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/solidus_admin/store_credits_controller.rb', line 93 def update_memo if @store_credit.update(memo: permitted_resource_params[:memo]) flash[:notice] = t('.success') else # Memo update failures are nearly impossible to trigger due to lack of validation. flash[:error] = t('.failure') end redirect_to after_update_path, status: :see_other end |