Answers.Body: <p>There was a bug in Craft where custom fields weren't being loaded when using the <a href="http://buildwithcraft.com/classreference/services/ElementsService" rel="nofollow">ElementsService</a> in the context of a console command.</p>
  
  <p>Just fixed it for the next (post <a href="http://buildwithcraft.com/updates#build2598" rel="nofollow">2.2.2598</a>) release.</p>
  
  <p>Am I'm not sure I'm following the locale issue.  Can you post that as a separate question with some more clarification?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-03T19:46:11.653Z
Answers.LastActivityDate: 2014-11-03T19:46:11.653Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm having trouble getting the elements service working correctly in a consolecommand. The same code works as expected in a controller, so I expect there is either a bug, or some extra config I'm missing.</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  class ShoppingCommand extends BaseCommand {
  
      public function actionListOrders() {
          $c = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
          //$c-&gt;locale = craft()-&gt;i18n-&gt;getPrimarySiteLocale();
          $c-&gt;section = 'orders';
          $c-&gt;limit = 5;
          foreach($c as $o) {
              print $o-&gt;orderId . ": " . $o-&gt;title . ", " . $o-&gt;price . "\n";
          }
      }
  }
  </code></pre>
  
  <p>running this results in the following</p>
  
  <pre><code>$ ./app/etc/console/yiic shopping listorders
  : blah,
  </code></pre>
  
  <p>running the same action with a Controller in the webapp results in the expected output:</p>
  
  <pre><code>10: blah, 123
  </code></pre>
  
  <p>Anyone have any ideas if it's possible to get around this? For now I can just build my functionality into a controller, but it would be much more convenient if I could run it from the command line like this. </p>
  
  <p>Also, there is another issue with this relating to the locale. Originally I needed to use the commented out line above because my site's default locale was <code>en</code> where as the consolecommands default to <code>en_us</code> and without forcing the locale my queries were not returning any results at all. I changed my default locale to <code>en_us</code> to test whether the other issue was something to do with the locales as well, but it didn't make a difference.</p>
  
  <p>Cheers</p>
  
  <p>-Tristan</p>
  
Tags: <plugin-development>
Title: Issues using the elements service in console commands
ThreadText: # Issues using the elements service in console commands
  
  (Asked by: username_0 on 2014-11-03)
  
  I'm having trouble getting the elements service working correctly in a consolecommand. The same code works as expected in a controller, so I expect there is either a bug, or some extra config I'm missing.
  
  ```
  <?php
  namespace Craft;
  
  class ShoppingCommand extends BaseCommand {
  
      public function actionListOrders() {
          $c = craft()->elements->getCriteria(ElementType::Entry);
          //$c->locale = craft()->i18n->getPrimarySiteLocale();
          $c->section = 'orders';
          $c->limit = 5;
          foreach($c as $o) {
              print $o->orderId . ": " . $o->title . ", " . $o->price . "\n";
          }
      }
  }
  
  ```
  
  running this results in the following
  
  ```
  $ ./app/etc/console/yiic shopping listorders
  : blah,
  
  ```
  
  running the same action with a Controller in the webapp results in the expected output:
  
  ```
  10: blah, 123
  
  ```
  
  Anyone have any ideas if it's possible to get around this? For now I can just build my functionality into a controller, but it would be much more convenient if I could run it from the command line like this.
  
  Also, there is another issue with this relating to the locale. Originally I needed to use the commented out line above because my site's default locale was `en` where as the consolecommands default to `en_us` and without forcing the locale my queries were not returning any results at all. I changed my default locale to `en_us` to test whether the other issue was something to do with the locales as well, but it didn't make a difference.
  
  Cheers
  
  -username_0
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-11-03. Score: 0 | Accepted answer
  
  There was a bug in Craft where custom fields weren't being loaded when using the [ElementsService](http://buildwithcraft.com/classreference/services/ElementsService) in the context of a console command.
  
  Just fixed it for the next (post [2.2.2598](http://buildwithcraft.com/updates#build2598)) release.
  
  Am I'm not sure I'm following the locale issue. Can you post that as a separate question with some more clarification?
  
  
  ---
  
  