{"record":{"id":"e10aa5a400029e18","repo":"spree/spree","slug":"spree-stocklocation-stock-item-is-deprecated-and","errorCode":null,"errorMessage":"Spree::StockLocation#stock_item is deprecated and will be removed in Spree 6.1. Use #stock_level instead.","messagePattern":"Spree::StockLocation#stock_item is deprecated and will be removed in Spree 6\\.1\\. Use #stock_level instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spree/core/app/models/spree/stock_location.rb","lineNumber":88,"sourceCode":"    #\n    # @return [StockLevel] Corresponding StockLevel for the StockLocation's variant.\n    def stock_level(variant_id)\n      stock_levels.where(variant_id: variant_id).order(:id).first\n    end\n\n    def stocks?(variant)\n      stock_levels.exists?(variant: variant)\n    end\n\n    # @deprecated Use {#stock_levels}; removed in 6.1.\n    def stock_items\n      Spree::Deprecation.warn('Spree::StockLocation#stock_items is deprecated and will be removed in Spree 6.1. Use #stock_levels instead.')\n      stock_levels\n    end\n\n    # @deprecated Use {#stock_level}; removed in 6.1.\n    def stock_item(variant_id)\n      Spree::Deprecation.warn('Spree::StockLocation#stock_item is deprecated and will be removed in Spree 6.1. Use #stock_level instead.')\n      stock_level(variant_id)\n    end\n\n    # @deprecated Use {#set_up_stock_level}; removed in 6.1.\n    def set_up_stock_item(variant)\n      Spree::Deprecation.warn('Spree::StockLocation#set_up_stock_item is deprecated and will be removed in Spree 6.1. Use #set_up_stock_level instead.')\n      set_up_stock_level(variant)\n    end\n\n    # @deprecated Use {#stock_level_or_create}; removed in 6.1.\n    def stock_item_or_create(variant_or_variant_id)\n      Spree::Deprecation.warn('Spree::StockLocation#stock_item_or_create is deprecated and will be removed in Spree 6.1. Use #stock_level_or_create instead.')\n      stock_level_or_create(variant_or_variant_id)\n    end\n\n    # Attempts to look up StockLevel for the variant, and creates one if not found.\n    #\n    # @param variant Variant instance or Variant ID","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/spree/spree/blob/06bf66a8684b9de03210bbb2ddc8c1f5ba522fa2/spree/core/app/models/spree/stock_location.rb#L70-L106","documentation":"Spree 6.0 renamed the StockItem model to StockLevel (typed-stock-movements rework: table prefixes si_→sl_, endpoints /stock_levels). StockLocation#stock_item is a one-release bridge that delegates to #stock_level and emits this warning on every call; it is deleted in 6.1, after which calls raise NoMethodError.","triggerScenarios":"Calling stock_location.stock_item(variant_id) — e.g. a stock-sync rake task, extension code, serializer or console snippet written against Spree 5.x that looked up the per-location stock row before reading/writing count_on_hand.","commonSituations":"An extension or copied app code written for Spree <= 5.6 running on a 6.0 app; CSV import jobs that ensured a stock item existed per location; a third-party gem that has not shipped a Spree 6-compatible release yet.","solutions":["Replace the call with stock_location.stock_level(variant_id) — identical argument shape (variant or variant id) and identical return type (Spree::StockLevel).","If the call is inside a gem you cannot edit, upgrade that gem to its Spree 6-compatible version, or fork and change that one line.","For code that must run on both 5.x and 6.0, bridge with location.respond_to?(:stock_level) and prefer the new name.","As a stopgap wrap the call in Spree::Deprecation.silence { ... } while you schedule the rename — never leave this in place past the 6.1 upgrade."],"exampleFix":"// before\nstock_item = stock_location.stock_item(variant.id)\n\n// after\nstock_level = stock_location.stock_level(variant.id)","handlingStrategy":"fallback","validationCode":"if stock_location.respond_to?(:stock_level)\n  level = stock_location.stock_level(variant.id)\nelse\n  level = stock_location.stock_item(variant.id)\nend","typeGuard":"def spree_stock_level_api?(stock_location)\n  stock_location.respond_to?(:stock_level)\nend","tryCatchPattern":null,"preventionTips":["Run the test suite with Spree::Deprecation.behavior = :raise so every deprecated call fails CI instead of logging.","Grep app code, initializers, lib/tasks and factories for 'stock_item' before each Spree upgrade — bridges last exactly one release.","Prefer StockLocation verbs and Stock::Quantifier over hand-rolled per-location lookups; they are the stable 6.0 surface."],"tags":["spree","deprecation","stock","stock-location","rename"],"backgroundTag":"deprecated-method-rename","analyzedSha":"06bf66a8684b9de03210bbb2ddc8c1f5ba522fa2","analyzedAt":"2026-08-21T14:59:48.125Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}