{"record":{"id":"96fc62ae33fd55af","repo":"spree/spree","slug":"spree-order-ensure-line-items-are-in-stock-is-dep","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spree/core/app/models/spree/order.rb","lineNumber":709,"sourceCode":"    # If so add error and restart checkout.\n    # @deprecated Completion validation lives in\n    #   {Spree::Checkout::DefaultRequirements} (the +discontinued+ stock\n    #   error). Removed in 6.1.\n    def ensure_line_item_variants_are_not_discontinued\n      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.')\n      if line_items.any? { |li| !li.variant || li.variant.discontinued? }\n        errors.add(:base, Spree.t(:discontinued_variants_present))\n        false\n      else\n        true\n      end\n    end\n\n    # @deprecated Completion validation lives in\n    #   {Spree::Checkout::DefaultRequirements} (the +out_of_stock+ stock\n    #   error). Removed in 6.1.\n    def ensure_line_items_are_in_stock\n      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.')\n      if insufficient_stock_lines.present?\n        errors.add(:base, Spree.t(:insufficient_stock_lines_present))\n        false\n      else\n        true\n      end\n    end\n\n    def use_all_coupon_codes\n      Spree::Deprecation.warn('Spree::Order#use_all_coupon_codes is deprecated and will be removed in Spree 6.1. Use Spree::CouponCodes::CouponCodesHandler instead.')\n      Spree::CouponCodes::CouponCodesHandler.new(order: self).use_all_codes\n    end\n\n    normalizes :coupon_code, with: ->(code) { code.to_s.strip.downcase.presence }\n\n    def can_add_coupon?\n      Spree::Deprecation.warn('Spree::Order#can_add_coupon? is deprecated and will be removed in Spree 6.1. Use Spree::Promotion.order_activatable? instead.')\n      Spree::Promotion.order_activatable?(self)","sourceCodeStart":691,"sourceCodeEnd":727,"githubUrl":"https://github.com/spree/spree/blob/06bf66a8684b9de03210bbb2ddc8c1f5ba522fa2/spree/core/app/models/spree/order.rb#L691-L727","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the call — Carts::Complete enforces the out_of_stock completion error.","For showing warnings in the UI without blocking, read order.insufficient_stock_lines (not deprecated) instead.","Add a validate hook handler on the Complete workflow if you need custom completion-time stock policy."],"exampleFix":"# before\nreturn unless order.ensure_line_items_are_in_stock\n\n# after — UI reads, completion enforces\norder.insufficient_stock_lines.each { |item| warn_user(item) }\nresult = Spree.carts_complete_workflow.call(cart: cart)","handlingStrategy":"validation","validationCode":"# Find pre-completion stock guards\n# rg \"ensure_line_items_are_in_stock\" app lib --type ruby","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read order.insufficient_stock_lines for UI warnings — it is not deprecated.","Let Carts::Complete enforce the out_of_stock error instead of duplicating the check in controllers.","Write specs for both the warning path and the blocked-completion path before deleting old guards."],"tags":["spree","deprecation","ruby","orders","checkout","stock"],"backgroundTag":"deprecated-api-usage","analyzedSha":"06bf66a8684b9de03210bbb2ddc8c1f5ba522fa2","analyzedAt":"2026-08-21T14:59:48.125Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}