{"id":1796,"date":"2021-06-14T11:18:15","date_gmt":"2021-06-14T11:18:15","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/programmatically-check-if-stock-is-decreased-when-order-is-placed-in-magento-2\/"},"modified":"2025-07-16T17:42:15","modified_gmt":"2025-07-16T12:12:15","slug":"programmatically-check-if-stock-is-decreased-when-order-is-placed-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/programmatically-check-if-stock-is-decreased-when-order-is-placed-in-magento-2\/","title":{"rendered":"How to Programmatically Check if Stock is Decreased When Order is Placed in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Managing well-structured inventory is one of the most challenging and troublesome tasks for any E-commerce store owner. However,&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-inventory-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 inventory management<\/a>&nbsp;can\u2019t be overlooked as it is one of the crucial factors that define the success of any business.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento 2 store owner applies various tactics to manage an accurate inventory that guarantees better control and planning of production and sales. Maintaining an inventory grid by generating an inventory report is one such tactic to handle inventory effectively.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While working with such inventory-related tasks, a developer often needs to check the selected value of the default Magento 2 inventory management system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento 2\u00a0offers various options to manage stock and inventory. One such option is a \u201c<strong>Decrease Stock When Order is Placed<\/strong>\u201d from\u00a0<strong>Stores > Settings > Configuration > Catalog > Inventory > Stock Options\u00a0<\/strong>that decreases the quantity in stock when order is placed if set to \u201cYes\u201d and vice versa, for \u201cNo\u201d.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2021\/05\/ss-2-1024x486.png\" alt=\"How to Programmatically Check if Stock is Decreased When Order is Placed in Magento 2\" class=\"wp-image-15039\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Now, what if you want to add a column in your inventory records grid that displays the particular product\u2019s salable quantity changes?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You first have to&nbsp;<strong><em>programmatically check if stock is decreased when order is placed in Magento 2&nbsp;<\/em><\/strong>and then set a necessary condition to display a record of stock set to \u201cYes\u201d in the \u201cDecrease Stock When Order is Placed\u201d option. And even for such situations you can also&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/programmatically-check-whether-stock-is-managed-for-particular-product-in-magento-2\/\">Programmatically Check Whether Stock is Managed for Particular Product in Magento 2<\/a>&nbsp;or not so that you can maintain the stock and not let it decrease.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check out the below code to do so.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may need to do the same with the \u201cManage Stock\u201d option too, and for that, you can refer to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/programmatically-check-whether-stock-is-managed-for-particular-product-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Programmatically Check Whether Stock is Managed for Particular Product in Magento 2<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Programmatically Check if Stock is Decreased When Order is Placed in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below code in your helper 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 VendorModuleHelper;\n\nuse MagentoCatalogInventoryModelConfiguration;\nuse MagentoFrameworkAppHelperAbstractHelper;\nuse MagentoFrameworkAppHelperContext;\nuse MagentoFrameworkExceptionNoSuchEntityException;&lt;?php\n\nnamespace Vendor\\Module\\Helper;\n\nuse Magento\\CatalogInventory\\Model\\Configuration;\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\Framework\\Exception\\NoSuchEntityException;\nuse Magento\\Store\\Model\\StoreManagerInterface;\n\n\/**\n * Class IsStockDecreaseWhenOrderIsPlaced\n *\/\nclass IsStockDecreaseWhenOrderIsPlaced extends AbstractHelper\n{\n    \/**\n     * @var Configuration\n     *\/\n    private $inventoryConfiguration;\n    \/**\n     * @var StoreManagerInterface\n     *\/\n    private $storeManager;\n\n    \/**\n     * IsStockDecreaseWhenOrderIsPlaced constructor.\n     * @param Configuration $inventoryConfiguration\n     * @param StoreManagerInterface $storeManager\n     * @param Context $context\n     *\/\n    public function __construct(Configuration $inventoryConfiguration, StoreManagerInterface $storeManager, Context $context)\n    {\n        parent::__construct($context);\n        $this->inventoryConfiguration = $inventoryConfiguration;\n        $this->storeManager = $storeManager;\n    }\n\n    \/**\n     * @return bool\n     * @throws NoSuchEntityException\n     *\/\n    public function isStockDecreaseWhenOrderIsPlaced()\n    {\n        return $this->inventoryConfiguration->canSubtractQty($this->storeManager->getStore()->getId());\n    }\n}\nuse MagentoStoreModelStoreManagerInterface;\n\n\/**\n * Class IsStockDecreaseWhenOrderIsPlaced\n *\/\nclass IsStockDecreaseWhenOrderIsPlaced extends AbstractHelper\n{\n    \/**\n     * @var Configuration\n     *\/\n    private $inventoryConfiguration;\n    \/**\n     * @var StoreManagerInterface\n     *\/\n    private $storeManager;\n\n    \/**\n     * IsStockDecreaseWhenOrderIsPlaced constructor.\n     * @param Configuration $inventoryConfiguration\n     * @param StoreManagerInterface $storeManager\n     * @param Context $context\n     *\/\n    public function __construct(Configuration $inventoryConfiguration, StoreManagerInterface $storeManager, Context $context)\n    {\n        parent::__construct($context);\n        $this->inventoryConfiguration = $inventoryConfiguration;\n        $this->storeManager = $storeManager;\n    }\n\n    \/**\n     * @return bool\n     * @throws NoSuchEntityException\n     *\/\n    public function isStockDecreaseWhenOrderIsPlaced()\n    {\n        return $this->inventoryConfiguration->canSubtractQty($this->storeManager->getStore()->getId());\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t forget to share this post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Managing well-structured inventory is one of the most challenging and troublesome tasks for any E-commerce store owner. However,&nbsp;Magento 2 inventory management&nbsp;can\u2019t be overlooked as it&#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-1796","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1796","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=1796"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1796\/revisions"}],"predecessor-version":[{"id":18051,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1796\/revisions\/18051"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}