Magento – Get product source in MSI

magento2.3.1msiproduct

I have 3 stocks, each having its own source. Every source is assigned to some or the other product.

When an order is placed with one of these products, how do I find out the source for each product in the order.

I tried using the method-

$orderItem->getProduct()->getQuantityAndStockStatus()

returns

{ ["is_in_stock"]=> bool(false) ["qty"]=> float(0) } 

However,

$orderItem->getProduct()->isInStock()

returns

true

Any ideas would be appreciated. Thanks!

Best Answer

The way how you are getting a product stock status is deprecated, as you are trying to retrieve multiple sources via the CatalogInventory APIs which are single stock by their nature. Instead, you supposed to use the API brought by new inventory:

Read the Inventory documentation for more details - https://github.com/magento-engcom/msi/wiki/Overview

Related Topic