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.

Call function to fetch the list of sales channels,

Output:

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.