Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-06T00:08:58.703Z
Answers.LastActivityDate: 2017-05-06T00:08:58.703Z
Answers.UserDisplayName: Jeremy Daalder
Body: <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>
  
Tags: <plugin-craftcommerce>
Title: Edit custom field value inside "commerce_orders.onBeforeSaveOrder" event
ThreadText: # 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....
  
  
  ---
  
  