I work on Magento 2.4 and I'd like to enable programmatically for selected products "Manage Stock" option and set status Out Of stock. Like here: Product Manage Stock settings

But I did not found how it should be done in Magento higher than 2.4 I found that \Magento\CatalogInventory\Api\StockRegistryInterface is deprecated. Product model setStocData() also is deprecated.

How it should be done without use of any deprecated classes?

1 Answer 1


yes i too checked and the classes are deprecated perhaps you can try this - from your question i get to know that you want to set the "Manage Stock" and "Stock Status" for a product.

Please follow the below code where i hit the rest API endpoint and the product's stock settings gets changes.You can also follow this in your PHP file or JS file by hitting this API.

endpoint = http://local.magento243.com/rest/V1/products/24-MB01

HTTP Method = PUT

Body request params =

{ "product": { "extension_attributes": { "stock_item": { "is_in_stock": false, "manage_stock": false } } } }

Authorisation is also needed as Bearer token.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.