I am building a Magento 2 module that makes changes to stock information.

Bearing in mind stock management APIs are different in Magento depending on if MSI is being used or not, what is the best practice to write different functionality for each scenario?

Is it as simple as detecting if MSI in enabled something like

if ($this->moduleManager->isOutputEnabled('Magento_Inventory')) {
    // Do MSI code
} else {
    // Do none-MSI code

Or is there a better way?


The approach you mentioned (isOutputEnabled()) is now deprecated and shouldn't be used.

Also, MSI functionality comprises a list of multiple modules which you can check in the official documentation - https://devdocs.magento.com/extensions/inventory-management/.

I would recommend checking the app/etc/config.php modules status by calling the same module manager class with the isEnabled() method and possibly (depending on what you need to achieve) in conjunction with a check if there are stocks and sources defined in your shop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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