Skip to content

How to Programmatically Adjust Out-of-Stock Threshold for Products in Magento 2

I’m currently working on a Magento 2 project that utilizes MSI and I’m trying to programmatically update the Out-of-Stock Threshold for each of my products. While I am able to adjust the quantity available using the setQuantity method on SourceItemInterface, I haven’t found a way to modify the Out-of-Stock Threshold at the product or source level through code.

I understand that Out-of-Stock Threshold and backorder settings are usually configured globally or per stock in the Magento admin. However, my project requires that these settings be dynamically adjusted for individual products based on various factors, including external inventory data.

I’ve already explored the SourceItemInterface and related APIs, but it seems they don’t directly support modifying the Out-of-Stock Threshold. My current approach involves adjusting inventory quantities via SourceItemsSaveInterface, which works well for updating stock levels but doesn’t address the threshold issue.

Thank you for your help!