spree/spree · warning

Spree::Order#ensure_line_items_are_in_stock is deprecated an

Error message

Spree::Order#ensure_line_items_are_in_stock is deprecated and will be removed in Spree 6.1. Completion validation lives in Spree::Checkout::Requirements.

What it means

The in-stock twin of the discontinued check: Spree::Order#ensure_line_items_are_in_stock warns and still works (adds the insufficient_stock_lines_present error to :base, returns true/false), but completion validation now lives in Spree::Checkout::DefaultRequirements (the out_of_stock stock error) and the shell is removed in 6.1.

Source

Thrown at spree/core/app/models/spree/order.rb:709

    # If so add error and restart checkout.
    # @deprecated Completion validation lives in
    #   {Spree::Checkout::DefaultRequirements} (the +discontinued+ stock
    #   error). Removed in 6.1.
    def ensure_line_item_variants_are_not_discontinued
      Spree::Deprecation.warn('Spree::Order#ensure_line_item_variants_are_not_discontinued is deprecated and will be removed in Spree 6.1. Completion validation lives in Spree::Checkout::Requirements.')
      if line_items.any? { |li| !li.variant || li.variant.discontinued? }
        errors.add(:base, Spree.t(:discontinued_variants_present))
        false
      else
        true
      end
    end

    # @deprecated Completion validation lives in
    #   {Spree::Checkout::DefaultRequirements} (the +out_of_stock+ stock
    #   error). Removed in 6.1.
    def ensure_line_items_are_in_stock
      Spree::Deprecation.warn('Spree::Order#ensure_line_items_are_in_stock is deprecated and will be removed in Spree 6.1. Completion validation lives in Spree::Checkout::Requirements.')
      if insufficient_stock_lines.present?
        errors.add(:base, Spree.t(:insufficient_stock_lines_present))
        false
      else
        true
      end
    end

    def use_all_coupon_codes
      Spree::Deprecation.warn('Spree::Order#use_all_coupon_codes is deprecated and will be removed in Spree 6.1. Use Spree::CouponCodes::CouponCodesHandler instead.')
      Spree::CouponCodes::CouponCodesHandler.new(order: self).use_all_codes
    end

    normalizes :coupon_code, with: ->(code) { code.to_s.strip.downcase.presence }

    def can_add_coupon?
      Spree::Deprecation.warn('Spree::Order#can_add_coupon? is deprecated and will be removed in Spree 6.1. Use Spree::Promotion.order_activatable? instead.')
      Spree::Promotion.order_activatable?(self)

View on GitHub (pinned to 06bf66a868)

Solutions

  1. Remove the call — Carts::Complete enforces the out_of_stock completion error.
  2. For showing warnings in the UI without blocking, read order.insufficient_stock_lines (not deprecated) instead.
  3. Add a validate hook handler on the Complete workflow if you need custom completion-time stock policy.

Example fix

# before
return unless order.ensure_line_items_are_in_stock

# after — UI reads, completion enforces
order.insufficient_stock_lines.each { |item| warn_user(item) }
result = Spree.carts_complete_workflow.call(cart: cart)
Defensive patterns

Strategy: validation

Validate before calling

# Find pre-completion stock guards
# rg "ensure_line_items_are_in_stock" app lib --type ruby

Prevention

When it happens

Trigger: Custom checkout flows calling order.ensure_line_items_are_in_stock before allowing payment or completion — the standard pre-6.0 pattern for blocking overselling checkout steps.

Common situations: Ported storefront checkouts with explicit stock guards; extensions double-checking stock before capture; upgraded code where the guard is now redundant with Carts::Complete validation.

Related errors


AI-assisted analysis of spree/spree@06bf66a868 (2026-08-21). Data as JSON: /api/errors/96fc62ae33fd55af. Report an issue: GitHub.