Answers.Body: <p>As soon as you change the mini template for your order numbers, Commerce will start using that new thing...if you want the numbers part to reset, just use a new sequence name in the template.</p>
  <p>You can start it at a particular number, too, if you wish, e.g. to start at 2022-000005:</p>
  <pre><code>{{ object.dateCompleted|date('y') ~ '-' ~ (seq(&quot;some_new_name&quot;,6) + 5) }}
  </code></pre>
  <p>If you want to remap existing orders to this format, you will probably be best doing that via some migration/module code...</p>
  <p>Basically...loop over the orders in question and:</p>
  <pre class="lang-php prettyprint-override"><code>$order-&gt;reference = $whatever;
  Craft::$app-&gt;getElements()-&gt;saveElement($order);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-10T00:33:37.980Z
Answers.LastActivityDate: 2022-01-10T00:33:37.980Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>By default, Commerce uses the <code>{{number[:7]}}</code> format to set an order's reference on order completion. Now (after the site already has orders and I can no longer reset the site's data), I need to use a different format for existing orders, because we're going to use it as the invoice number, which has to be sequential.</p>
  <p>Is there a way to <code>reset</code> the order's references in such a way that I can set the format to <code>{{object.dateCompleted|date('y')}}-{{ seq(object.dateCompleted|date('y'), 6) }}</code>, run a script (for instance) and give all orders a new reference (2021-000001, 2021-000002, ...)?</p>
  
Tags: <plugin-craftcommerce>
Title: How do I reset all Commerce order references?
ThreadText: # How do I reset all Commerce order references?
  
  (Asked by: username_0 on 2022-01-05)
  
  By default, Commerce uses the `{{number[:7]}}` format to set an order's reference on order completion. Now (after the site already has orders and I can no longer reset the site's data), I need to use a different format for existing orders, because we're going to use it as the invoice number, which has to be sequential.
  
  Is there a way to `reset` the order's references in such a way that I can set the format to `{{object.dateCompleted|date('y')}}-{{ seq(object.dateCompleted|date('y'), 6) }}`, run a script (for instance) and give all orders a new reference (2021-000001, 2021-000002, ...)?
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-01-10. Score: 2
  
  As soon as you change the mini template for your order numbers, Commerce will start using that new thing...if you want the numbers part to reset, just use a new sequence name in the template.
  
  You can start it at a particular number, too, if you wish, e.g. to start at 2022-000005:
  
  ```
  {{ object.dateCompleted|date('y') ~ '-' ~ (seq("some_new_name",6) + 5) }}
  
  ```
  
  If you want to remap existing orders to this format, you will probably be best doing that via some migration/module code...
  
  Basically...loop over the orders in question and:
  
  ```php
  $order->reference = $whatever;
  Craft::$app->getElements()->saveElement($order);
  
  ```
  
  
  ---
  
  