Answers.Body: <p>This feels a bit dirty, but you can actually do this directly in a Twig template like this:</p>
  <pre><code>{% set order = craft.orders.id(123).one() %}
  {% do order.setAttributes({orderStatusId: 4}, false) %}
  {% do craft.app.getElements().saveElement(order) %}
  </code></pre>
  <p>-- naturally you'd need a way to fetch which order you want to update, but you could easily grab that from your POST data or from the URL or localStorage or whatever.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-02T14:50:05.890Z
Answers.Text: This is just what I was looking for. Obviously better to use a controller, however for our purposes this will work. Many thanks for providing a solution.
Answers.UserDisplayName: Andrew F
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-01T15:18:37.547Z
Answers.LastActivityDate: 2020-10-13T09:17:15.650Z
Answers.LastEditDate: 2020-10-13T09:17:15.650Z
Answers.UserDisplayName: James Smith
Body: <p>Following on from this question <a href="https://craftcms.stackexchange.com/questions/35897/commerce-how-to-update-an-order-status-via-the-frontend">Commerce: How to update an order status via the frontend</a></p>
  <p>We'd like to make it easy for delivery drivers to update the status of a craft commerce order, from a frontend page. Doing it via the CP on mobile is a bit cumbersome as it involves multiple steps.</p>
  <p>We've created a user group call couriers.</p>
  <pre><code>{% extends '_layouts/_logistics' %}
  
  {% block logistics %}
      {% if currentUser and currentUser.isInGroup('courier') %}
          {% include 'logistics/_orders' %}
      {% else %}
          {% redirect 'account' %}
      {% endif %}
  {% endblock %}
  </code></pre>
  <p>In the _orders include we'd like to show a list of orders, each with a 'Mark as Delivered' button, which can be clicked as the orders are fullfilled.</p>
  <pre><code>&lt;dl&gt;
      {% if order.shippingAddress %}
          {% include 'shop/_includes/addresses/address' with { address: order.shippingAddress } %}
      {% endif %}
      &lt;dt&gt;{{ order.reference }}&lt;/dt&gt;
  &lt;/dl&gt;
  &lt;form method=&quot;POST&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;&quot;&gt;
      {{ redirectInput('logistics') }}
      {{ csrfInput() }}
      &lt;input type=&quot;hidden&quot; name=&quot;orderStatusId&quot; value=&quot;4&quot;&gt;
      &lt;input class=&quot;button button--primary&quot; type=&quot;submit&quot; value='Mark as Delivered'&gt;
  &lt;/form&gt;
  </code></pre>
  <p>I'm wondering if this can be done, without the need to build a plugin or module? Else is there a plan to include the ability to do this in a future Craft Commerce release.</p>
  <p>Many thanks,</p>
  <p>Andrew</p>
  
Tags: <ecommerce><plugin-craftcommerce3><status>
Title: Craft Commerce — Update order status from frontend?
ThreadText: # Craft Commerce — Update order status from frontend?
  
  (Asked by: username_0 on 2020-08-31)
  
  Following on from this question [Commerce: How to update an order status via the frontend](https://craftcms.stackexchange.com/questions/35897/commerce-how-to-update-an-order-status-via-the-frontend)
  
  We'd like to make it easy for delivery drivers to update the status of a craft commerce order, from a frontend page. Doing it via the CP on mobile is a bit cumbersome as it involves multiple steps.
  
  We've created a user group call couriers.
  
  ```
  {% extends '_layouts/_logistics' %}
  
  {% block logistics %}
      {% if currentUser and currentUser.isInGroup('courier') %}
          {% include 'logistics/_orders' %}
      {% else %}
          {% redirect 'account' %}
      {% endif %}
  {% endblock %}
  
  ```
  
  In the \_orders include we'd like to show a list of orders, each with a 'Mark as Delivered' button, which can be clicked as the orders are fullfilled.
  
  ```
  <dl>
      {% if order.shippingAddress %}
          {% include 'shop/_includes/addresses/address' with { address: order.shippingAddress } %}
      {% endif %}
      <dt>{{ order.reference }}</dt>
  </dl>
  <form method="POST">
      <input type="hidden" name="action" value="">
      {{ redirectInput('logistics') }}
      {{ csrfInput() }}
      <input type="hidden" name="orderStatusId" value="4">
      <input class="button button--primary" type="submit" value='Mark as Delivered'>
  </form>
  
  ```
  
  I'm wondering if this can be done, without the need to build a plugin or module? Else is there a plan to include the ability to do this in a future Craft Commerce release.
  
  Many thanks,
  
  username_0
  
  **Tags:** ecommerce, plugin-craftcommerce3, status
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-09-01. Score: 2 | Accepted answer
  
  This feels a bit dirty, but you can actually do this directly in a Twig template like this:
  
  ```
  {% set order = craft.orders.id(123).one() %}
  {% do order.setAttributes({orderStatusId: 4}, false) %}
  {% do craft.app.getElements().saveElement(order) %}
  
  ```
  
  -- naturally you'd need a way to fetch which order you want to update, but you could easily grab that from your POST data or from the URL or localStorage or whatever.
  
  > **Comments:**
  > **username_0**: This is just what I was looking for. Obviously better to use a controller, however for our purposes this will work. Many thanks for providing a solution.  
  
  ---
  
  