<p>That looks right, but I think you may need to set the value of that field to '1' - looking in the <code>craft_content</code> table, it seems switches are stored as <code>0</code> and <code>1</code>.</p>

<pre><code>      $order = $event-&gt;params["order"];
      $order-&gt;setContentFromPost(array(
          'ediCheck' =&gt; 1,
      ));
</code></pre>

<p>If that still doesn't work, try throwing in a <code>craft()-&gt;commerce_orders-&gt;saveOrder($order);</code> at the end of your function.  It shouldn't be needed though as it should fall through to the <code>saveOrder</code> it's going to do anyway....</p>

CC BY-SA 3.0
2017-05-06T00:08:58.703Z
2017-05-06T00:08:58.703Z
Jeremy Daalder
<p>I would like to edit custom Lightswitch field value to true inside of event on order save</p>

<pre><code>          $order = $event-&gt;params["order"];
          $order-&gt;setContentFromPost(array(
              'ediCheck' =&gt; true,
          ));

          $order-&gt;getContent()-&gt;setAttributes(array(
              'ediCheck' =&gt; true,
          ));
</code></pre>

<p>Tried following but the value still stays the same.</p>

<p>Also If there is an documentation file on following that I maybe missed would also be helpful.</p>

<plugin-craftcommerce>
Edit custom field value inside "commerce_orders.onBeforeSaveOrder" event
# Edit custom field value inside "commerce_orders.onBeforeSaveOrder" event

(Asked by: username_0 on 2017-05-05)

I would like to edit custom Lightswitch field value to true inside of event on order save
          $order = $event->params["order"];
          $order->setContentFromPost(array(
              'ediCheck' => true,
          ));

          $order->getContent()->setAttributes(array(
              'ediCheck' => true,
          ));

Tried following but the value still stays the same.
Also If there is an documentation file on following that I maybe missed would also be helpful.

**Tags:** plugin-craftcommerce


---

## 1 answers

### Answer by username_1 on 2017-05-06. Score: 2

That looks right, but I think you may need to set the value of that field to '1' - looking in the craft_content table, it seems switches are stored as 0 and 1.
      $order = $event->params["order"];
      $order->setContentFromPost(array(
          'ediCheck' => 1,
      ));

If that still doesn't work, try throwing in a craft()->commerce_orders->saveOrder($order); at the end of your function.  It shouldn't be needed though as it should fall through to the saveOrder it's going to do anyway....


---

