Answers.Body: <p>This can be achieved with</p>
  
  <pre><code>Event::on(
              Order::class, 
              Order::EVENT_AFTER_COMPLETE_ORDER, 
              function(Event $e) {
  
                  $order = $e-&gt;sender;
  
                  $order-&gt;isCompleted = false;
                  Craft::$app-&gt;getElements()-&gt;saveElement($order, false);
  
              }
          );
  </code></pre>
  
  <p>But I'm not sure it's actually a good idea anyway.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-23T09:15:11.167Z
Answers.LastActivityDate: 2019-07-23T09:15:11.167Z
Answers.UserDisplayName: foamcow
Body: <p>The default behaviour for commerce is to mark the <code>isCompleted</code> flag on an order to <code>true</code> once the order has been paid for.</p>
  
  <p>I have need to alter this behaviour and only want to mark an order as Complete via manual intervention of a site admin - or after a predefined date has passed.</p>
  
  <p>Is it possible to set the isCompleted flag from within a custom module? 
  Right now, I'm listening to the <code>EVENT_AFTER_ORDER_PAID</code> then attempting to set the isCompleted flag and save the order.</p>
  
  <p>What I can't figure out is how to save the order!</p>
  
  <p>Code so far, for what it's worth:</p>
  
  <pre><code>Event::on(
              Order::class, 
              Order::EVENT_AFTER_ORDER_PAID, 
              function(Event $e) {
                  $order = $e-&gt;sender;
  
                  $order-&gt;isCompleted = false; // no idea if this is correct
  
                  $order-&gt;saveOrder(); // this doesn't work
              }
          );
  </code></pre>
  
Tags: <plugin-craftcommerce2><modules>
Title: How can I set the isCompleted status of an order from within a custom module?
ThreadText: # How can I set the isCompleted status of an order from within a custom module?
  
  (Asked by: username_0 on 2019-07-22)
  
  The default behaviour for commerce is to mark the `isCompleted` flag on an order to `true` once the order has been paid for.
  
  I have need to alter this behaviour and only want to mark an order as Complete via manual intervention of a site admin - or after a predefined date has passed.
  
  Is it possible to set the isCompleted flag from within a custom module?
  Right now, I'm listening to the `EVENT_AFTER_ORDER_PAID` then attempting to set the isCompleted flag and save the order.
  
  What I can't figure out is how to save the order!
  
  Code so far, for what it's worth:
  
  ```
  Event::on(
              Order::class, 
              Order::EVENT_AFTER_ORDER_PAID, 
              function(Event $e) {
                  $order = $e->sender;
  
                  $order->isCompleted = false; // no idea if this is correct
  
                  $order->saveOrder(); // this doesn't work
              }
          );
  
  ```
  
  **Tags:** plugin-craftcommerce2, modules
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-07-23. Score: 1
  
  This can be achieved with
  
  ```
  Event::on(
              Order::class, 
              Order::EVENT_AFTER_COMPLETE_ORDER, 
              function(Event $e) {
  
                  $order = $e->sender;
  
                  $order->isCompleted = false;
                  Craft::$app->getElements()->saveElement($order, false);
  
              }
          );
  
  ```
  
  But I'm not sure it's actually a good idea anyway.
  
  
  ---
  
  