Answers.Body: <pre><code>$discount = new \craft\commerce\models\Discount();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-09T10:57:17.297Z
Answers.Text: Thanks. Is that the same as: use craft\commerce\models\Discount as DiscountModel; $discount = new DiscountModel(); ?
Answers.UserDisplayName: phaetons
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-09T18:20:09.210Z
Answers.Text: @phaetons It's the same. In the latter, you're using a namespace alias: https://secure.php.net/manual/en/language.namespaces.importing.php
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-09T23:38:12.560Z
Answers.Text: Thanks Brad! I really need to update my PHP7 skills...
Answers.UserDisplayName: phaetons
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-09T10:50:29.980Z
Answers.LastActivityDate: 2019-01-09T10:50:29.980Z
Answers.UserDisplayName: Luke Holder
Body: <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>
  
Tags: <plugin-development><plugin-craftcommerce><models>
Title: How to get instance of DiscountModel in Commerce 2?
ThreadText: # 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**: @username_0 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 username_2! I really need to update my PHP7 skills...  
  
  ---
  
  