{"id":3420,"date":"2024-02-22T07:30:30","date_gmt":"2024-02-22T07:30:30","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/learn-how-to-change-product-salable-quantity-in-magento-2\/"},"modified":"2025-03-17T05:15:07","modified_gmt":"2025-03-17T05:15:07","slug":"learn-how-to-change-product-salable-quantity-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/learn-how-to-change-product-salable-quantity-in-magento-2\/","title":{"rendered":"Learn How to Change Product Salable Quantity in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you are a Magento 2 user facing an issue changing your salable quantity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t worry; here is the solution for you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Salable quantity is the sum of available resources grouped in stocks.&nbsp; They change when an order is placed if these salables are staying the same in the backend of your&nbsp;<a href=\"https:\/\/business.adobe.com\/products\/magento\/magento-commerce.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento<\/a>&nbsp;2 admin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is how you can fix this issue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Change Product Salable Quantity in Magento 2?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In order to set the salable quantity of a product, look at the table = \u201ccataloginventory_stock_item\u201d , in this the field = \u201cqty\u201d. Here it&nbsp;will automatically set the saleable qty.<\/li>\n\n\n\n<li>Now, write a manual script placed in the Magento root directory. This will set the qty of the product using the product ID.<\/li>\n\n\n\n<li>To get the ID, you can use the product repository to load the product and store it in an array.<\/li>\n\n\n\n<li>Set the qty filed using the product ID, which is mentioned below.<\/li>\n\n\n\n<li>Keep in mind that the indexer is saved in the schedule as it might slow down the process if it is saved on update.<\/li>\n\n\n\n<li>Or if you know how to use Model and Resource Model to set the qty, use these Classes:<br>1.\u00a0<code>\u00a0<em>Magento\\CatalogInventory\\Model\\Stock\\ItemFactory<\/em><\/code><br>2.\u00a0<code>\u00a0<em>Magento\\CatalogInventory\\Model\\ResourceModel\\Stock\\Item<\/em><\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Now, see this code.<\/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=\"\">use Magento\\Framework\\App\\Bootstrap;\n\nrequire __DIR__ . '\/..\/app\/bootstrap.php';\n\n$bootstrap = Bootstrap::create(BP, $_SERVER);\n$objectManager = $bootstrap->getObjectManager();\n$state = $objectManager->get('Magento\\Framework\\App\\State');\n$state->setAreaCode('adminhtml');\n\/\/Required for custom code ends\n\nsetProductQty($objectManager);\n\nfunction setProductQty($objectManager)\n{\n    $productId = [\"1\", \"2\", \"3\", \"4\", \"5\"];\n    foreach ($productId as $itemId) {\n        try {\n            $stockModel = $objectManager->get('Magento\\CatalogInventory\\Model\\Stock\\ItemFactory')->create();\n            $stockResource = $objectManager->get('Magento\\CatalogInventory\\Model\\ResourceModel\\Stock\\Item');\n            $stockResource->load($stockModel, $itemId,\"product_id\");\n            $stockModel->setQty(\"90\");\n            $stockResource->save($stockModel);\n        } catch (Exception $e) {\n            echo $e->getMessage();\n        }\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And that is it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you will be able to see the desired changes. Try this yourself, and if you have any doubts, drop a comment, and I will surely help you out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are a Magento 2 user facing an issue changing your salable quantity. Don\u2019t worry; here is the solution for you. Salable quantity is&#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-3420","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/3420","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=3420"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/3420\/revisions"}],"predecessor-version":[{"id":9293,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/3420\/revisions\/9293"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=3420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=3420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=3420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}