{"record":{"id":"aa672668a59d1e47","repo":"spree/spree","slug":"spree-storecredit-order-by-priority-is-deprecated","errorCode":null,"errorMessage":"Spree::StoreCredit.order_by_priority is deprecated and will be removed in Spree 6.1. Use .oldest_first instead.","messagePattern":"Spree::StoreCredit\\.order_by_priority is deprecated and will be removed in Spree 6\\.1\\. Use \\.oldest_first instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spree/core/app/models/spree/store_credit.rb","lineNumber":43,"sourceCode":"    belongs_to :originator, polymorphic: true, optional: true\n\n    has_many :store_credit_events, class_name: 'Spree::StoreCreditEvent'\n    has_many :payments, as: :source, class_name: 'Spree::Payment'\n    has_many :orders, through: :payments, class_name: 'Spree::Order'\n\n    validates :currency, :store, presence: true\n    validates :amount, numericality: { greater_than: 0 }\n    validates :amount_used, numericality: { greater_than_or_equal_to: 0 }\n    validate :amount_used_less_than_or_equal_to_amount\n    validate :amount_authorized_less_than_or_equal_to_amount\n\n    delegate :email, to: :created_by, prefix: true, allow_nil: true\n\n    # Redemption order: the oldest credit is spent first.\n    scope :oldest_first, -> { order(:created_at, :id) }\n    # @deprecated Removed in Spree 6.1 — store credit types are gone; use {.oldest_first}.\n    scope :order_by_priority, lambda {\n      Spree::Deprecation.warn('Spree::StoreCredit.order_by_priority is deprecated and will be removed in Spree 6.1. Use .oldest_first instead.')\n      oldest_first\n    }\n\n    scope :not_authorized, -> { where(amount_authorized: 0) }\n    scope :not_used, -> { where(\"#{Spree::StoreCredit.table_name}.amount_used < #{Spree::StoreCredit.table_name}.amount\") }\n    scope :available, -> { not_authorized.not_used }\n    scope :with_gift_card, -> { where(originator_type: 'Spree::GiftCard') }\n    scope :without_gift_card, -> { where(originator_type: [nil, '']).or(where.not(originator_type: 'Spree::GiftCard')) }\n\n    after_save :store_event\n    before_destroy :validate_no_amount_used\n\n    attr_accessor :action, :action_amount, :action_originator, :action_authorization_code\n\n    extend Spree::DisplayMoney\n    money_methods :amount, :amount_used, :amount_remaining, :amount_authorized\n\n    def amount=(amount)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/spree/spree/blob/06bf66a8684b9de03210bbb2ddc8c1f5ba522fa2/spree/core/app/models/spree/store_credit.rb#L25-L61","documentation":"StoreCredit.order_by_priority was the 5.x scope that spent credits by their type's priority. 6.0 deletes store credit types entirely, so redemption order is now fixed: oldest first. The old scope delegates to .oldest_first (order(:created_at, :id)) and warns; removed in 6.1.","triggerScenarios":"Calling Spree::StoreCredit.order_by_priority — typically checkout code or extensions selecting which credits to capture, e.g. Spree::StoreCredit.available.order_by_priority.each { ... }.","commonSituations":"Store-credit spenders/prioritizers copied from 5.x; extensions implementing custom credit redemption; specs asserting capture order.","solutions":["Replace .order_by_priority with .oldest_first — the resulting order is identical to what production now uses.","Delete any custom prioritizer that sorted by type priority; priority no longer exists.","Update extensions to their Spree 6 releases.","Bridge dual-version with respond_to?(:oldest_first) on the class."],"exampleFix":"# before\ncredits = store_credits.available.order_by_priority\n\n# after\ncredits = store_credits.available.oldest_first","handlingStrategy":"fallback","validationCode":"scope = if Spree::StoreCredit.respond_to?(:oldest_first)\n  Spree::StoreCredit.available.oldest_first\nelse\n  Spree::StoreCredit.available.order_by_priority\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not build custom credit prioritizers — redemption order is fixed oldest-first in 6.0.","Assert capture order in specs against created_at rather than type priority.","Raise deprecations in CI so legacy scope calls surface immediately."],"tags":["spree","deprecation","store-credit","scope","rename"],"backgroundTag":"deprecated-method-rename","analyzedSha":"06bf66a8684b9de03210bbb2ddc8c1f5ba522fa2","analyzedAt":"2026-08-21T14:59:48.125Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}