{"id":1744,"date":"2021-05-02T11:07:19","date_gmt":"2021-05-02T11:07:19","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-product-quantity-information-in-magento-2\/"},"modified":"2025-05-22T10:34:58","modified_gmt":"2025-05-22T05:04:58","slug":"get-product-quantity-information-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-product-quantity-information-in-magento-2\/","title":{"rendered":"How to Get Product Quantity Information in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">One of the most troublesome jobs in eCommerce store management is to control all the data in the inventory and get the required one when needed. Every store owner encounters inventory management challenges at one point or another.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, today\u2019s market is more customer-centric than ever, and having a more thorough inventory strategy to manage inventory in your warehouse is becoming a necessity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Handling product quantity is the most essential factor for multi-store inventory management especially when your store has more than one warehouse or source. You can also&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/programmatically-check-whether-stock-is-managed-for-particular-product-in-magento-2\/\">check programmatically whether stock is managed for particular product<\/a>&nbsp;or is in need to get managed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose, you have one source in Chicago and the other in New York and you have the same product at both sources. Now, what if you want to keep track of an inventory of both sources? How can you find out the quantity of a particular product at both warehouses? How can you alert the admin about low product quantity?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In such a case, use the below method to&nbsp;<em><strong>get product quantity information in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get Product Quantity Information in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below code in your&nbsp;<strong>helper<\/strong>&nbsp;file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Module\\Helper;\n\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\InventoryConfigurableProductAdminUi\\Model\\GetQuantityInformationPerSource;\n\n\/**\n * Class GetQuantityInformationForProduct\n *\/\nclass GetQuantityInformationForProduct extends AbstractHelper\n{\n    \/**\n     * @var GetQuantityInformationPerSource\n     *\/\n    private $getQuantityInformationPerSource;\n\n    \/**\n     * GetQuantityInformationForProduct constructor.\n     * @param GetQuantityInformationPerSource $getQuantityInformationPerSource\n     * @param Context $context\n     *\/\n    public function __construct(GetQuantityInformationPerSource $getQuantityInformationPerSource, Context $context)\n    {\n        parent::__construct($context);\n        $this->getQuantityInformationPerSource = $getQuantityInformationPerSource;\n    }\n\n    \/**\n     * @param $productSku\n     * @return array\n     *\/\n    public function getQuantityInformationForProduct($productSku)\n    {\n        return $this->getQuantityInformationPerSource->execute($productSku);\n    }\n\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have set this code, you get the array data as shown below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Array\n(\n    [0] => Array\n        (\n            [source_code] => source_2\n            [quantity_per_source] => 1215\n            [source] => New York\n            [status] => 1\n        )\n    [1] => Array\n        (\n            [source_code] => source_3\n            [quantity_per_source] => 12297\n            [source] => Chicago\n            [status] => 1\n        )\n)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above log displays that 1215 quantity is there at the New York and 12297 quantity is there at Chicago.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Also Read:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/meetanshi.com\/blog\/e-commerce-returns-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">Top 9 Ways for Successful E-commerce Returns Management [2022]<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/meetanshi.com\/blog\/magento-2-inventory-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Inventory Management<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>One of the most troublesome jobs in eCommerce store management is to control all the data in the inventory and get the required one when&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1744","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1744"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1744\/revisions"}],"predecessor-version":[{"id":14349,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1744\/revisions\/14349"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}