Answers.Body: <p>You can use the same technique to set the line item data like this:</p>
  <pre><code>{% set order = craft.orders.id(123).one() %}
  
  {% for lineItem in order.lineItems %}
      {% do lineItem.setAttributes({lineItemStatusId: 2}, false) %}
  {% endfor %}
  
  {% do order.setAttributes({
      orderStatusId: 4,
      lineItems: order.lineItems
  }, false) %}
  
  {% do craft.app.getElements().saveElement(order) %}
  </code></pre>
  <p>^ That would set all line items in an order to the same status... I imagine you have some kind of interface where you can either update a single line item at a time or mark several at once and press a submit button, so in that scenario you'll probably want to add some conditionals inside the loop to check that the line item id you're on matches say, the line item id passed in through the URL or through POST data or whatever so that just the right one(s) get updated</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-13T09:14:28.590Z
Answers.LastActivityDate: 2020-10-13T09:14:28.590Z
Answers.UserDisplayName: James Smith
Body: <p>I'm building a simplified interface that is only going to be used by employees preparing the orders. They are in a usergroup that has the right permissions to update orders.
  I'm building this because updating an 'order status' or 'line item status' from the controlpanel is too finicky to do from a smartphone or tablet.</p>
  <p>I've found how to update an order status <a href="https://craftcms.stackexchange.com/questions/36114/craft-commerce-update-order-status-from-frontend">here</a> and got that working nicely.</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>What I don't know how to do is how to update the <a href="https://craftcms.com/docs/commerce/3.x/custom-order-statuses.html#line-item-statuses" rel="nofollow noreferrer">lineItemStatus</a>.
  I'll probably have to fetch the order first then the lineItem id and then update the lineItemStatus attribute, but I have no idea how to even start.</p>
  <p>Any help putting me in the right direction is greatly appreciated!</p>
  <p>*I also know this would be better to do with a module or plugin, but alas, I don't write php.</p>
  
Tags: <plugin-craftcommerce><order>
Title: How to update the lineItemStatus of an order on the front end with twig?
ThreadText: # How to update the lineItemStatus of an order on the front end with twig?
  
  (Asked by: username_0 on 2020-10-12)
  
  I'm building a simplified interface that is only going to be used by employees preparing the orders. They are in a usergroup that has the right permissions to update orders.
  I'm building this because updating an 'order status' or 'line item status' from the controlpanel is too finicky to do from a smartphone or tablet.
  
  I've found how to update an order status [here](https://craftcms.stackexchange.com/questions/36114/craft-commerce-update-order-status-from-frontend) and got that working nicely.
  
  ```
  {% set order = craft.orders.id('123').one() %}
  {% do order.setAttributes({'orderStatusId': 4}, false) %}
  {% do craft.app.getElements().saveElement(order) %}
  
  ```
  
  What I don't know how to do is how to update the [lineItemStatus](https://craftcms.com/docs/commerce/3.x/custom-order-statuses.html#line-item-statuses).
  I'll probably have to fetch the order first then the lineItem id and then update the lineItemStatus attribute, but I have no idea how to even start.
  
  Any help putting me in the right direction is greatly appreciated!
  
  \*I also know this would be better to do with a module or plugin, but alas, I don't write php.
  
  **Tags:** plugin-craftcommerce, order
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-10-13. Score: 2 | Accepted answer
  
  You can use the same technique to set the line item data like this:
  
  ```
  {% set order = craft.orders.id(123).one() %}
  
  {% for lineItem in order.lineItems %}
      {% do lineItem.setAttributes({lineItemStatusId: 2}, false) %}
  {% endfor %}
  
  {% do order.setAttributes({
      orderStatusId: 4,
      lineItems: order.lineItems
  }, false) %}
  
  {% do craft.app.getElements().saveElement(order) %}
  
  ```
  
  ^ That would set all line items in an order to the same status... I imagine you have some kind of interface where you can either update a single line item at a time or mark several at once and press a submit button, so in that scenario you'll probably want to add some conditionals inside the loop to check that the line item id you're on matches say, the line item id passed in through the URL or through POST data or whatever so that just the right one(s) get updated
  
  
  ---
  
  