获取自定义库存产品数量

Get custom stock product quantity

我使用此代码通过给定的 ID 检索产品数量

$stockItem = $objectManager->get('\Magento\CatalogInventory\Model\Stock\StockItemRepository');
$productId =  10858;
$productStock = $stockItem->get($productId);
$productStock->getData();

此代码有效,return 结果

array (
  'item_id' => '10858',
  'product_id' => '10962',
  'stock_id' => '1',
  'qty' => '0.0000',
  'min_qty' => '0.0000',
  ...
)

但我需要通过 stock_id = 2 而不是默认库存 (id: 1) 来检索信息 有办法做到这一点,使用这个代码?

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$productId = 1;

$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
                                    $product_qty = $StockState->getStockQty($productId);