Get Sales Channels Data For a Stock in MSI Magento 2.

Get Sales Channels list for a given stock using Extension attributes of Multi store Inventory stocks data.

Sales Channels is a list of website for your online store, You have to choose for your stock. If your site contains only a single website then you have only one sales channel.

You can fetch sales channel extension attributes using the getSalesChannels() method.

Retrieve Object of Inventory Stocks by its id. Native Magento MSI have Default Stock with Sales channel code is base(Main Website)

Use Interface Magento\InventoryApi\Api\StockRepositoryInterface

First load a Stock Object, after Retrieving object fetch extension attributes of sales channel by the given code snippet.

namespace Jesadiya\SalesChannels\Model;

use Exception;
use Psr\Log\LoggerInterface;
use Magento\InventoryApi\Api\StockRepositoryInterface;

class SalesChannels
     * @var StockRepositoryInterface
    private $stockRepository;

     * @var LoggerInterface
    private $logger;

    public function __construct(
        StockRepositoryInterface $stockRepository,
        LoggerInterface $logger
    ) {
        $this->stockRepository = $stockRepository;
        $this->logger = $logger;

     * @return array|null
    public function getSalesChannel()
        $salesChannelsData = [];
        try {
            $stockData = $this->stockRepository->get(1); // 1 for Default Stock

            foreach ($stockData->getExtensionAttributes()->getSalesChannels() as $salesChannel) {
                $salesChannelsData[$salesChannel['type']][] = $salesChannel['code'];
        } catch (Exception $exception) {

        return $salesChannelsData;

Call function to fetch the list of sales channels,

$salesChannelList = $this->getSalesChannel();
echo "<pre>";print_r($salesChannelList)


array (size=1)
  'website' => 
    array (size=2)
      0 => string 'base' (length=4)
      1 => string 'canada_website' (length=14)

I have assigned base and Canada website to the Default Stock.

You can see a list of Sales Channels from Admin panel Navigation Tab,

Stores -> Inventory -> Stocks.
Edit Default Stock from a list of Stocks and Check Sales Channels tabs.

sales channels MSI Magento 2
sales channels

Output display as two sales channels for Default Stock in Multi store Inventory.