inventory
inventory copied to clipboard
BulkInventoryTransfer fails for new inventory sources when products have no source item
Preconditions (*)
- Adobe Commerce 2.4.7-p4
- Sample data installed
- Some products created via rest API
Steps to reproduce (*)
- Create two new inventory sources
- Create a new inventory stock
- Assign the two new inventory sources to the stock
- Navigate to the products list in the admin panel
- Select all items and choose to "Transfer Inventory to Source"
- Choose to transfer to one of the new inventory sources, and check to unassign from the original source
Expected result (*)
- Inventory should be transferred and a success message should display
Actual result (*)
- Error message is displayed
Warning: Trying to access array offset on value of type null in {path}/vendor/magento/module-inventory-catalog/Model/ResourceModel/BulkInventoryTransfer.php on line 131 - Inventory is not transferred
Investigation
The code from the following method looks off:
https://github.com/magento/inventory/blob/997162df13e950d8492da6ce3a181430085bfc84/InventoryCatalog/Model/ResourceModel/BulkInventoryTransfer.php#L112
When $dstSourceItemQty is null, which seems likely to be the case for a brand new inventory source, it is by default set to 0:
$dstSourceItemQty = $dstSourceItem === null ? 0.0 : (float) $dstSourceItem[SourceItemInterface::QUANTITY];
As a result, the first elseif in this conditional passes, which means that it will try to read the status array key from $dstSourceItem, which is null, which causes the error (line 131).
if ($orgSourceItem !== null) {
$status = (int) $orgSourceItem[SourceItemInterface::STATUS];
} elseif ($dstSourceItemQty !== null) {
$status = (int) $dstSourceItem[SourceItemInterface::STATUS];
} else {
$status = (int) SourceItemInterface::STATUS_OUT_OF_STOCK;
}
It seems this method is not properly handing the use case of a new inventory source, and if you have products that were created by the API that might not yet have a source item in the database.
Hi @brian-labelle. Thank you for your report.
To speed up processing of this issue, make sure that you provided sufficient information.
Add a comment to assign the issue: @magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel.
Hello @brian-labelle ,
Thank you for the detailed report and for your collaboration.
We attempted to reproduce the issue on the 2.4 develop branch, and we were able to successfully reproduce it. Please find the reference screenshot attached.
Steps to Reproduce:
- Create two new inventory sources.
- Create a new inventory stock.
- Assign the two new inventory sources to the stock.
- Navigate to the products list in the Admin panel.
- Select all items and choose “Transfer Inventory to Source.”
- Choose one of the newly created inventory sources as the target and select the option to unassign the original source.
Following these steps, we encountered the same issue. Therefore, we are marking this as Issue: Confirmed.
Thank you for bringing this to our attention. If you have a potential fix, we encourage you to submit a pull request—your contributions help improve Magento Open Source for everyone. If you need any assistance, please feel free to reach out.
Thank you!
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-16061 is successfully created for this GitHub issue.