{"id":12927,"date":"2021-09-22T14:13:28","date_gmt":"2021-09-22T08:43:28","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=12927"},"modified":"2021-09-22T14:13:28","modified_gmt":"2021-09-22T08:43:28","slug":"product-stock-information","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-tutorials\/product-stock-information\/","title":{"rendered":"Magento 2 &#8211; How to Get Product Stock Information"},"content":{"rendered":"<p>In this post I am going to explain How to Get Product Stock Information in Magento 2.<\/p>\n<p>Use below methods to get product stock information in Magento 2 such as stock status, minimum stock quantity, minimum sale quantity, minimum quantity, etc.<\/p>\n<p>Using below code snippet you can get product stock data by passing product id.<\/p>\n<h5><strong>1. Using Dependency Injection<\/strong><\/h5>\n<p>Add below code snippet in Block class.<\/p>\n<pre>private $stockRegistry;\r\n\r\npublic function __construct(\r\n\\Magento\\CatalogInventory\\Api\\StockRegistryInterface $stockRegistry\r\n) {\r\n$this-&gt;stockRegistry = $stockRegistry;\r\n}\r\n\r\npublic function getStockInformation()\r\n{\r\nreturn $this-&gt;stockRegistry-&gt;getData();\r\n}\r\n<\/pre>\n<p>Add below code snippet in template file.<\/p>\n<pre>\/\/ product Id\r\n$productId = 1;\r\n\r\n$StockData = $block-&gt;getStockInformation($productId);\r\n\r\nif ($stockData &amp;&amp; count($stockData) &gt; 0) {\r\necho $manageStock = $stockData['manage_stock'];\r\necho $qty = $stockData['qty'];\r\necho $minQty = $stockData['min_qty'];\r\n}<\/pre>\n<h5><strong>2. Using Object Manager<\/strong><\/h5>\n<pre>$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\r\n$stockRegistry = $objectManager-&gt;get('Magento\\CatalogInventory\\Api\\StockRegistryInterface')-&gt;getStockItem($_product-&gt;getId());\r\n$stockData = $stockRegistry-&gt;getData();\r\n\r\nif ($stockData &amp;&amp; count($stockData) &gt; 0) {\r\necho $manageStock = $stockData['manage_stock'];\r\necho $qty = $stockData['qty'];\r\necho $minQty = $stockData['min_qty'];\r\n}\r\n<\/pre>\n<p>That\u2019s it. Enjoy Magento 2!!<\/p>\n<p>Check this <a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/set-default-values-system-configuration-fields\/\">Best Magento 2 Tutorial<\/a>.<\/p>\n<div class=\"angwp_12010 _ning_cont _ning_hidden _ning_outer _align_center responsive\" data-size=\"custom\" data-bid=\"12010\" data-aid=\"0\" style=\"max-width:800px; width:100%;height:inherit;\"><div class=\"_ning_label _left\" style=\"\"><\/div><div class=\"_ning_inner\" style=\"\"><a href=\"https:\/\/www.hiddentechies.com\/blog?_dnlink=12010&t=1775803898\" class=\"strack_cli _ning_link\" target=\"_blank\">&nbsp;<\/a><div class=\"_ning_elmt\"><img decoding=\"async\" src=\"https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/angwp\/items\/12010\/Banner-2.png\" \/><\/div><\/div><\/div><div class=\"clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>In this post I am going to explain How to Get Product Stock Information in Magento 2. Use below methods to get product stock information in Magento 2 such as stock status, minimum stock quantity, minimum sale quantity, minimum quantity, etc. Using below code snippet you can get product stock data by passing product id&#8230;. <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-tutorials\/product-stock-information\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":10,"featured_media":13127,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59,2138],"tags":[2347,2345,2346,2344,2348],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/12927"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=12927"}],"version-history":[{"count":10,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/12927\/revisions"}],"predecessor-version":[{"id":13126,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/12927\/revisions\/13126"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/13127"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=12927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=12927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=12927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}