Skip to content

fix(sales): admin reorder drops OOS items when backorders disabled (#39958)#40833

Open
lbajsarowicz wants to merge 2 commits into
magento:2.4-developfrom
lbajsarowicz:fix/39958-reorder-oos-stockregistry
Open

fix(sales): admin reorder drops OOS items when backorders disabled (#39958)#40833
lbajsarowicz wants to merge 2 commits into
magento:2.4-developfrom
lbajsarowicz:fix/39958-reorder-oos-stockregistry

Conversation

@lbajsarowicz

Copy link
Copy Markdown
Contributor

Description

On non-MSI stores with backorders disabled, Admin "Reorder" produced an
empty quote and the message This product is out of stock with all
order details missing. Create::initFromOrderItem calls
Quote::addProduct, which invokes Product::isSalable; StockRegistry
then reports is_in_stock=false for any product whose live stock has
depleted since the original order, and the item is silently skipped.
IsSuperMode does not help here: it only short-circuits
QuantityValidatorObserver, which fires later in the pipeline.

Enable Catalog\Helper\Product::skipSaleableCheck for the duration of
initFromOrder so the admin can rebuild the original order regardless
of current stock state. The flag is restored in a finally block so the
helper's state does not leak to other code paths in the same request.

Fixes #39958

Fixed Issues

Manual testing scenarios

  1. Non-MSI store with backorders disabled.
  2. Place an order for a product with stock quantity = 1.
  3. Disable the product or set qty to 0 so live stock cannot fulfil the original order.
  4. Go to admin and click Reorder on the original order.
  5. After this fix: admin reorder rebuilds the quote with the original items. Before: empty quote + "This product is out of stock" message.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (13 existing tests pass)
  • Changes to the codebase comply with technical guidelines

On non-MSI stores with backorders disabled, Admin "Reorder" produced an
empty quote and the message "This product is out of stock" with all
order details missing. Create::initFromOrderItem calls
Quote::addProduct, which invokes Product::isSalable; StockRegistry then
reports is_in_stock=false for any product whose live stock has
depleted since the original order, and the item is silently skipped.
IsSuperMode does not help here: it only short-circuits
QuantityValidatorObserver, which fires later in the pipeline.

Enable Catalog\Helper\Product::skipSaleableCheck for the duration of
initFromOrder so the admin can rebuild the original order regardless
of current stock state. The flag is restored in a finally block so the
helper's state does not leak to other code paths in the same request.

Fixes magento#39958
@m2-assistant

m2-assistant Bot commented May 25, 2026

Copy link
Copy Markdown

Hi @lbajsarowicz. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@lbajsarowicz

Copy link
Copy Markdown
Contributor Author

@magento run all tests

@lbajsarowicz lbajsarowicz changed the title fix(sales): admin reorder drops OOS items when backorders disabled fix(sales): admin reorder drops OOS items when backorders disabled (#39958) May 25, 2026
@engcom-Hotel engcom-Hotel added the Priority: P3 May be fixed according to the position in the backlog. label May 26, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard May 26, 2026
…jectManager

Replaces the inline $this->_objectManager->get(\Magento\Catalog\Helper\Product::class)
call inside initFromOrder() with a properly constructor-injected dependency.
The parameter is nullable with a null default to preserve BC for subclasses,
with an ObjectManager fallback in the constructor body following the existing
pattern used by other late-added dependencies in this class.

Updates the unit test to supply a mock of the helper directly via the
ObjectManagerHelper argument array, removing the objectManager->get stub.
@lbajsarowicz

Copy link
Copy Markdown
Contributor Author

@magento run all tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P3 May be fixed according to the position in the backlog. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

Admin Reorder Error When Product Is Out of Stock in Magento 2.4.7

2 participants