Class: Spree::Admin::StoreCreditsController

Inherits:
ResourceController show all
Defined in:
app/controllers/spree/admin/store_credits_controller.rb

Instance Method Summary collapse

Methods inherited from ResourceController

belongs_to, #destroy, #edit, #new, #update_positions

Methods included from SetsUserLanguageLocaleKey

#set_user_language_locale_key

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/spree/admin/store_credits_controller.rb', line 17

def create
  @store_credit = @user.store_credits.build(
    permitted_resource_params.merge({
      created_by: spree_current_user,
      action_originator: spree_current_user
    })
  )

  if @store_credit.save
    flash[:success] = flash_message_for(@store_credit, :successfully_created)
    redirect_to admin_user_store_credits_path(@user)
  else
    load_categories
    flash[:error] = "#{t('spree.admin.store_credits.unable_to_create')} #{@store_credit.errors.full_messages}"
    render :new
  end
end

#invalidateObject



61
62
63
64
65
66
67
68
# File 'app/controllers/spree/admin/store_credits_controller.rb', line 61

def invalidate
  @store_credit = @user.store_credits.find(params[:id])
  if @store_credit.invalidate(@store_credit_reason, spree_current_user)
    redirect_to admin_user_store_credit_path(@user, @store_credit)
  else
    render_edit_page
  end
end

#showObject



13
14
15
# File 'app/controllers/spree/admin/store_credits_controller.rb', line 13

def show
  @store_credit_events = @store_credit.store_credit_events.chronological
end

#updateObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/spree/admin/store_credits_controller.rb', line 35

def update
  @store_credit.assign_attributes(permitted_resource_params)
  @store_credit.created_by = spree_current_user

  if @store_credit.save
    respond_to do |format|
      format.json { render json: { message: flash_message_for(@store_credit, :successfully_updated) }, status: :ok }
    end
  else
    respond_to do |format|
      format.json { render json: { message: "#{t('spree.admin.store_credits.unable_to_update')} #{@store_credit.errors.full_messages}" }, status: :bad_request }
    end
  end
end

#update_amountObject



50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/spree/admin/store_credits_controller.rb', line 50

def update_amount
  @store_credit = @user.store_credits.find(params[:id])
  amount = params.require(:store_credit).require(:amount)
  if @store_credit.update_amount(amount, @store_credit_reason, spree_current_user)
    flash[:success] = flash_message_for(@store_credit, :successfully_updated)
    redirect_to admin_user_store_credit_path(@user, @store_credit)
  else
    render_edit_page
  end
end