Class: Spree::Admin::LoyaltyAccountsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/loyalty_accounts_controller.rb

Overview

Read-only support/diagnostic view — no create/edit/destroy for the account itself (see config/routes.rb: only: [:index]). The one real write action is #adjust_points, a deliberately narrow escape hatch for staff comping/correcting a balance, kept separate from normal CRUD so it always goes through SpreeLoyalty::Redemption-adjacent ledger bookkeeping rather than a raw balance edit.

Instance Method Summary collapse

Instance Method Details

#adjust_pointsObject



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

def adjust_points
   = SpreeLoyalty::Account.find(params[:account_id])
  points = params[:points].to_i
  note = params[:note].presence

  if points.zero?
    flash[:error] = 'Enter a non-zero number of points to adjust.'
  else
    SpreeLoyalty::Account.transaction do
      .transactions.create!(points: points, kind: SpreeLoyalty::Transaction::ADJUSTED, note: note)
      .update!(
        points_balance: .points_balance + points,
        lifetime_points_earned: .lifetime_points_earned + [points, 0].max
      )
    end
    flash[:success] = "Adjusted #{.user.email}'s balance by #{points} points."
  end

  redirect_to admin_loyalty_accounts_path
end

#model_classObject



10
11
12
# File 'app/controllers/spree/admin/loyalty_accounts_controller.rb', line 10

def model_class
  SpreeLoyalty::Account
end