Answers.Body: <pre><code>$order = \craft\commerce\elements\Order::find()-&gt;id($id)-&gt;one();
  
  if($order)
  {
    foreach ($order-&gt;getLineItems() as $item) {
     // $item-&gt;description
     // $item-&gt;qty
    }
  
    $billingAddress = $order-&gt;getBillingAddress();
    $shippingAddress = $order-&gt;getShippingAddress();
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-16T15:21:39.293Z
Answers.LastActivityDate: 2018-08-17T10:14:47.393Z
Answers.LastEditDate: 2018-08-17T10:14:47.393Z
Answers.UserDisplayName: Luke Holder
Body: <p>I want to write a plugin which writes all the order data into a CSV file.
  Unfortunately the documentation for Commerce 2 isn't quite complete yet so I have difficulties to find out how to do the following with a plugin (so I need to use PHP and not Twig).</p>
  
  <ol>
  <li>Get an order by ID.</li>
  <li>Get ordered items.</li>
  <li>Get the addresses for the order.</li>
  </ol>
  
  <p>Every help appreciated.</p>
  
Tags: <plugin-development><plugin-craftcommerce2>
Title: Craft Commerce 2 - get order data for plugin
ThreadText: # Craft Commerce 2 - get order data for plugin
  
  (Asked by: username_0 on 2018-08-16)
  
  I want to write a plugin which writes all the order data into a CSV file.
  Unfortunately the documentation for Commerce 2 isn't quite complete yet so I have difficulties to find out how to do the following with a plugin (so I need to use PHP and not Twig).
  
  1. Get an order by ID.
  2. Get ordered items.
  3. Get the addresses for the order.
  
  Every help appreciated.
  
  **Tags:** plugin-development, plugin-craftcommerce2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-16. Score: 4 | Accepted answer
  
  ```
  $order = \craft\commerce\elements\Order::find()->id($id)->one();
  
  if($order)
  {
    foreach ($order->getLineItems() as $item) {
     // $item->description
     // $item->qty
    }
  
    $billingAddress = $order->getBillingAddress();
    $shippingAddress = $order->getShippingAddress();
  }
  
  ```
  
  
  ---
  
  