Get source item data by SKU Multi Source Inventory(MSI) Magento 2

You can get sources item by product SKU by class \Magento\InventoryApi\Api\GetSourceItemsBySkuInterface

You can get source_item_id, source_code, sku, quantity and status

I have created a sample model to show you how can you get sources item by SKU

<?php

namespace Mageprince\Testing\Model;

class SourceListModel
{
    private $sourceItemsBySku;

    public function __construct(
        ...
        \Magento\InventoryApi\Api\GetSourceItemsBySkuInterface $sourceItemsBySku,
        ...
    ) {
        $this->sourceItemsBySku = $sourceItemsBySku;
    }

    public function getSourceItemBySku($sku)
    {
       return $this->sourceItemsBySku->execute($sku);
    }
}

Now you can use getSourcesBySku() function to get sources item by SKU

$sku = 'PIM-1023';
$sourceItemList = $this->getSourceItemBySku($sku);

foreach ($sourceItemList as $source) {
    print_r($source->getData());
}

Here is the sample output

Array
(
    [source_item_id] => 145
    [source_code] => test_store
    [sku] => PIM-1023
    [quantity] => 10.0000
    [status] => 1
)

Hope this will help you to get sources by product SKU.

Keep Sharing 🙂