Skip to content

How to set product OUT OF STOCK and enable Manage Stock for this product in Magento 2.4

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 MagentoCatalogInventoryApiStockRegistryInterface is deprecated. Product model setStocData() also is deprecated.

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