Home » Magento, Magento 26 June 2016

Magento 2: Get Product Stock Quantity and Other Stock Information

This article shows how to get stock quantity (qty) of a product in Magento 2. We can also fetch other stock information like minimum quantity (min_qty), minimum sale quantity (min_sale_qty), maximum sale quantity (max_sale_qty), see if a product is in stock (is_in_stock), etc.

We will be using Magento 2’s Service Layer for this task. Use of Service Layer is highly encouraged by Magento.

Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\CatalogInventory\Model\Stock\StockItemRepository class in the constructor of my module’s block class.


Now, we load the product by id and sku in template file.

Using Object Manager

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Subhash Patel

    Hi Mukesh,

    I have use example but it didn’t show anything. Please let me know how we can achieve this.


  • Robert

    Have a look at my response regarding a similar (incorrect) answer :) http://stackoverflow.com/a/42415002/688965

  • Thanks Robert :)

  • Slaviša Perišić

    Wrong code. you cannot get stock data based on product ID. You need stock item ID.

  • Mykhailo Shatilov

    Try use MagentoCatalogInventoryModelSpiStockRegistryProviderInterface

  • san

    how to get the grouped products total qty of each item magento 2

  • Aman

    Use this code form getting stock data :

    $stockitem = $objectManager->get(‘MagentoCatalogInventoryApiStockRegistryInterface’)->getStockItem($productId);

  • Nimesh pawar


  • Oğuz Can Sertel

    How can we get item_id ?

  • Oğuz Can Sertel