You can get source item details like Quantity, Status, Source item id, source code from the item Sku using Multi-source inventory (MSI) feature.
Useful Interface:
Magento\InventoryApi\Api\SourceItemRepositoryInterface
SourceItemRepositoryInterface used to find Source Items by SearchCriteria.
Code snippet to fetch source item details by SKU,
<? namespace Jesadiya\SourceItemData\Model; use Exception; use Psr\Log\LoggerInterface; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryApi\Api\SourceItemRepositoryInterface; class SourceItem { /** * @var SearchCriteriaBuilder */ private $searchCriteriaBuilder; /** * @var SourceItemRepositoryInterface */ private $sourceItemRepository; /** * @var LoggerInterface */ private $logger; public function __construct( SearchCriteriaBuilder $searchCriteriaBuilder, SourceItemRepositoryInterface $sourceItemRepository, LoggerInterface $logger ) { $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->sourceItemRepository = $sourceItemRepository; $this->logger = $logger; } /** * Retrieves links that are assigned to $stockId * * @param string $sku * @return SourceItemInterface[] */ public function getSourceItemDetailBySKU(string $sku): array { $searchCriteria = $this->searchCriteriaBuilder ->addFilter(SourceItemInterface::SKU, '24-UB02') ->create(); $result = $this->sourceItemRepository->getList($searchCriteria)->getItems(); return $result; } }
Call function to fetch data of source item,
$sku = '24-UB02'; $result = $this->getSourceItemDetailBySKU($sku); foreach ($result as $item) { print_r($item->getData()); }
Output:
Array ( [source_item_id] => 7 [source_code] => default [sku] => 24-UB02 [quantity] => 98.0000 [status] => 1 )
You can fetch the item source details information using the MSI inventory API module.