<p>All of Craft’s core services are available via the <code>Craft::$app-&gt;getServiceName()-&gt;callServiceMethod()</code> signature.</p>

<p>For example, the Elements service would be <code>Craft::$app-&gt;getElements()-&gt;saveElement()</code></p>

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

<pre><code>use craft/commerce/Plugin as Commerce;
// Maybe a class declaration, and inside your own method…
Commerce::getInstance()-&gt;getOrders()-&gt;getOrderByNumber('abc123...');
</code></pre>

CC BY-SA 4.0
2019-01-09T08:51:17.957Z
Ok, the 'as Commerce' did the trick, thank you!
phaetons
CC BY-SA 4.0
2019-01-08T17:26:04.190Z
2019-01-08T22:03:45.023Z
2019-01-08T22:03:45.023Z
August Miller
<p>I am migrating my plugin to Craft 3 / Commerce 2.</p>

<p>What is the best way to call another plugins method like <code>craft()-&gt;commerce_orders-&gt;getOrderByNumber($number)</code> from my plugins service?</p>

<plugin-development><migration><plugin-craftcommerce2>
Correct way to getOrderByNumber() from my Plugin in Commerce 2
# Correct way to getOrderByNumber() from my Plugin in Commerce 2

(Asked by: username_0 on 2019-01-08)

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?

**Tags:** plugin-development, migration, plugin-craftcommerce2


---

## 1 answers

### Answer by username_1 on 2019-01-08. Score: 1 | Accepted answer

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...');

> **Comments:**
> **username_0**: Ok, the 'as Commerce' did the trick, thank you!  

---

