Class: Spree::Admin::LoyaltyAccountsController
- Inherits:
-
ResourceController
- Object
- ResourceController
- Spree::Admin::LoyaltyAccountsController
- 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_points ⇒ Object
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 account = 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 account.transactions.create!(points: points, kind: SpreeLoyalty::Transaction::ADJUSTED, note: note) account.update!( points_balance: account.points_balance + points, lifetime_points_earned: account.lifetime_points_earned + [points, 0].max ) end flash[:success] = "Adjusted #{account.user.email}'s balance by #{points} points." end redirect_to admin_loyalty_accounts_path end |
#model_class ⇒ Object
10 11 12 |
# File 'app/controllers/spree/admin/loyalty_accounts_controller.rb', line 10 def model_class SpreeLoyalty::Account end |