Skip to content

Conversation

braders
Copy link

@braders braders commented Aug 25, 2025

Description (*)

Optimises Magento\InventoryBundleProduct\Model\GetBundleProductStockStatus (https://github.com/magento/inventory/blob/develop/InventoryBundleProduct/Model/GetBundleProductStockStatus.php) to be better optimised for the scenario where there are many child products, and the parent product is in stock.

Currently getAreSalableSelections gets the stock status for every SKU within an option in bulk:

return $this->areProductsSalableForRequestedQty->execute($skuRequests, $stockId);

This is where the inefficiency lies. Despite areProductsSalableForRequestedQty accepting an array of $skuRequests, it actually gets the stock status of each SKU syncronously. You can see that in https://github.com/magento/inventory/blob/develop/InventorySales/Model/AreProductsSalableForRequestedQty.php, where it actually just calls isProductSalableForRequestedQtyInterface->execute within a loop. Each call to isProductSalableForRequestedQtyInterface performs database queries, and this is a moderately expensive function.

This refactor changes the logic to only call isProductSalableForRequestedQtyInterface->execute the minimum possible number of times required to get the correct result.

Fixed Issues (if relevant)

  1. Fixes GetBundleProductStockStatus should be better optimised for the scenario where there are many child products, and the parent product is in stock #3435: GetBundleProductStockStatus should be better optimised for the scenario where there are many child products, and the parent product is in stock

Manual testing scenarios (*)

Test GetBundleProductStockStatus to ensure the same behaviour as before.

Note, that a site I maintain has been running this code in production (albeit on a Magento 2.4.4 installation) for some time, with no observed bugs.

Questions or comments

This could be seen as slightly academic as GetBundleProductStockStatus is not directly used in Magento core since 913287a#diff-b232ada4f1ab0a260b18a11a35d11d3337265f7bbb5eaba96dde557b4c2ced47. However, this optimisation will be useful for anyone using GetBundleProductStockStatus in extensions.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • [] All new or changed code is covered with unit/integration tests (if applicable)
  • [] All automated tests passed successfully (all builds are green)

@engcom-Hotel
Copy link
Collaborator

@magento run all tests

@engcom-Hotel
Copy link
Collaborator

Hello @braders,

We request you to please go through with this #3435 (comment).

Thanks

@engcom-Hotel engcom-Hotel self-assigned this Sep 16, 2025
@engcom-Hotel engcom-Hotel moved this from Ready for Review to Changes Requested in Inventory - Pull Request Progress Sep 16, 2025
@engcom-Hotel
Copy link
Collaborator

Hello @braders,

Gentle reminder for this PR.

Thank you

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

Projects

Status: Changes Requested

Development

Successfully merging this pull request may close these issues.

GetBundleProductStockStatus should be better optimised for the scenario where there are many child products, and the parent product is in stock

2 participants