❓Need explanation/possible bug (SourceSelection isVirtual)
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 357
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
In
https://github.com/magento/inventory/blob/d390a35fbf671e717e8f334fd700cd3fe0154ed5/InventoryShipping/Model/GetSourceSelectionResultFromInvoice.php#L108-L127
there's a condition filtering products
https://github.com/magento/inventory/blob/d390a35fbf671e717e8f334fd700cd3fe0154ed5/InventoryShipping/Model/GetSourceSelectionResultFromInvoice.php#L114
If I have an order with just simple products … wouldn't that return an empty array? I would expect this to return all simple products.
In our case it triggered an exception because there were no items thus the value was NULL.
```
PHP Fatal error: Uncaught TypeError: Return value of Magento\InventorySourceSelection\Model\Request\InventoryRequest::getItems() must be of the type array, null returned in vendor/magento/module-inventory-source-selection/Model/Request/InventoryRequest.php:102
Stack trace:
#0 vendor/magento/module-inventory-source-selection-api/Model/Algorithms/Result/GetDefaultSortedSourcesResult.php(97): Magento\InventorySourceSelection\Model\Request\InventoryRequest->getItems()
#1 vendor/magento/module-inventory-source-selection/Model/Algorithms/PriorityBasedAlgorithm.php(73): Magento\InventorySourceSelectionApi\Model\Algorithms\Result\GetDefaultSortedSourcesResult->execute(Object(Magento\InventorySourceSelection\Model\Request\InventoryRequest), Array)
#2 vendor/magento/module-inventory-source-selection-api/Model/SourceSelectionService.php(61): Magento\InventorySourceSelection\M in vendor/magento/module-inventory-source-selection/Model/Request/InventoryRequest.php on line 102
```
The reason it's NULL is caused by this class's definition of $items
https://github.com/magento/inventory/blob/d390a35fbf671e717e8f334fd700cd3fe0154ed5/InventorySourceSelection/Model/Request/InventoryRequest.php#L26-L29
which is then skipped to be set as an array here
https://github.com/magento/inventory/blob/d390a35fbf671e717e8f334fd700cd3fe0154ed5/InventorySourceSelection/Model/Request/InventoryRequest.php#L76-L86
Here's also a reference to https://github.com/magento-engcom/msi/issues/1524
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with InventoryShipping/Model/GetSourceSelectionResultFromInvoice.php around lines 108-127 and InventorySourceSelection/Model/Request/InventoryRequest.php around lines 26-29 and 76-86. Trace an order containing only simple products, confirm whether filtering leaves no items, and verify that getItems() cannot return null; done means the behavior and required correction are established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100