1

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.

1 Answer 1

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....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.