🔥 Just Launched! Werra Premium Template for HyväSee it in Action

Learn How to Change Product Salable Quantity in Magento 2

By Sanjay JethvaUpdated on Mar 17, 2025 2 min read

If you are a Magento 2 user facing an issue changing your salable quantity.

Don’t worry; here is the solution for you.

Salable quantity is the sum of available resources grouped in stocks.  They change when an order is placed if these salables are staying the same in the backend of your Magento 2 admin.

Here is how you can fix this issue.

How to Change Product Salable Quantity in Magento 2?

  • In order to set the salable quantity of a product, look at the table = “cataloginventory_stock_item” , in this the field = “qty”. Here it will automatically set the saleable qty.
  • Now, write a manual script placed in the Magento root directory. This will set the qty of the product using the product ID.
  • To get the ID, you can use the product repository to load the product and store it in an array.
  • Set the qty filed using the product ID, which is mentioned below.
  • Keep in mind that the indexer is saved in the schedule as it might slow down the process if it is saved on update.
  • Or if you know how to use Model and Resource Model to set the qty, use these Classes:
    1.  Magento\CatalogInventory\Model\Stock\ItemFactory
    2.  Magento\CatalogInventory\Model\ResourceModel\Stock\Item

Now, see this code.

use Magento\Framework\App\Bootstrap;

require __DIR__ . '/../app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');
//Required for custom code ends

setProductQty($objectManager);

function setProductQty($objectManager)
{
    $productId = ["1", "2", "3", "4", "5"];
    foreach ($productId as $itemId) {
        try {
            $stockModel = $objectManager->get('Magento\CatalogInventory\Model\Stock\ItemFactory')->create();
            $stockResource = $objectManager->get('Magento\CatalogInventory\Model\ResourceModel\Stock\Item');
            $stockResource->load($stockModel, $itemId,"product_id");
            $stockModel->setQty("90");
            $stockResource->save($stockModel);
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
}

And that is it.

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.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.