<pre><code>$discount = new \craft\commerce\models\Discount();
</code></pre>

CC BY-SA 4.0
2019-01-09T10:57:17.297Z
Thanks. Is that the same as: use craft\commerce\models\Discount as DiscountModel; $discount = new DiscountModel(); ?
phaetons
CC BY-SA 4.0
2019-01-09T18:20:09.210Z
@phaetons It's the same. In the latter, you're using a namespace alias: https://secure.php.net/manual/en/language.namespaces.importing.php
Brad Bell
CC BY-SA 4.0
2019-01-09T23:38:12.560Z
Thanks Brad! I really need to update my PHP7 skills...
phaetons
CC BY-SA 4.0
2019-01-09T10:50:29.980Z
2019-01-09T10:50:29.980Z
Luke Holder
<p>In Commerce i got an instance of DiscountModel Class as follows:</p>

<pre><code>$discount = new Commerce_DiscountModel();
</code></pre>

<p>Is this the right way in Commerce 2?</p>

<pre><code>use craft\commerce\models\Discount as DiscountModel;
...
$discount = DiscountModel::instance();
</code></pre>

<plugin-development><plugin-craftcommerce><models>
How to get instance of DiscountModel in Commerce 2?
# How to get instance of DiscountModel in Commerce 2?

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

In Commerce i got an instance of DiscountModel Class as follows:
$discount = new Commerce_DiscountModel();

Is this the right way in Commerce 2?
use craft\commerce\models\Discount as DiscountModel;
...
$discount = DiscountModel::instance();

**Tags:** plugin-development, plugin-craftcommerce, models

---

## 1 answers

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

$discount = new \craft\commerce\models\Discount();

> **Comments:**
> **username_0**: Thanks. Is that the same as: use craft\commerce\models\Discount as DiscountModel; $discount = new DiscountModel(); ?  
> **username_2**: @phaetons It's the same. In the latter, you're using a namespace alias: https://secure.php.net/manual/en/language.namespaces.importing.php  
> **username_0**: Thanks Brad! I really need to update my PHP7 skills...  

---

