1

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!

1 Answer 1

1

I found it. In StockItemInterface you can use setMinQty.

$stockItem->setUseConfigMinQty(false);
$stockItem->setMinQty($outOfStockThreshold);
$stockItem->save();

Note : You absolutely need to set the useConfigMinQty to false or else it will use the default Magento value. Also you need to set a negative value or it will stay at 0.

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.