3

After placing an order, my module calls an external API.

If success from external API, I need to update the order status.

I know how to update status in Magento 1 but how do you do this in Magento 2?

Thanks

1 Answer 1

2

Use \Magento\Sales\Api\OrderRepositoryInterface::get and \Magento\Sales\Api\OrderRepositoryInterface::save. This is public API of sales module and after future Magento releases will not change, so your custom module will not be broken.

Magento 1 style (manipulations with models an resource models directly from third party modules) should not be used in case when suitable public API is available (such classes/methods are marked with @api tag). Such approach will lead to custom module being broken after the next Magento 2 releases.

2
  • thanks for your response. Sorry, not sure if I was clear. I'm calling the external API within a custom Magento module (app/code/mymodule) and after return from the call I update the order status in the custom Magento module. With this approach ok to still call \Magento\Framework\App\ObjectManager::getInstance()? Also, after getting instance of OM, I'm using using "load()" method but "save" method is not found. What am I doing wrong.
    – user20719
    Commented Dec 11, 2015 at 19:39
  • 1
    Object manager should not be used directly, inject dependencies via construct. Also take a look at devdocs.magento.com/guides/v2.0/extension-dev-guide/… Commented Dec 11, 2015 at 21:43

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.