2

I am migrating my plugin to Craft 3 / Commerce 2.

What is the best way to call another plugins method like craft()->commerce_orders->getOrderByNumber($number) from my plugins service?

1

All of Craft’s core services are available via the Craft::$app->getServiceName()->callServiceMethod() signature.

For example, the Elements service would be Craft::$app->getElements()->saveElement()

In the case of other plugins, most will make their Singleton “instance” available as a property on (or method of) their primary plugin class:

use craft/commerce/Plugin as Commerce;
// Maybe a class declaration, and inside your own method…
Commerce::getInstance()->getOrders()->getOrderByNumber('abc123...');
  • Ok, the 'as Commerce' did the trick, thank you! – phaetons Jan 9 '19 at 8:51

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.