<p>When you take a look at the <code>BookingsController</code> you can see exactly what happens when you need to mark an order as complete</p>

<pre class="lang-PHP prettyprint-override"><code>public function actionCompleteOrder(): Response
{
    $this-&gt;requireAcceptsJson();
    $orderId = Craft::$app-&gt;getRequest()-&gt;getParam('orderId');

    $order = Plugin::getInstance()-&gt;getOrders()-&gt;getOrderById($orderId);

    if ($order &amp;&amp; !$order-&gt;isCompleted &amp;&amp; $order-&gt;markAsComplete()) {
        $date = new \DateTime($order-&gt;dateOrdered);
        return $this-&gt;asJson(['success' =&gt; true, 'dateOrdered' =&gt; $date]);
    }

    return $this-&gt;asErrorJson(Craft::t('commerce', 'Could not mark the order as completed.'));
}
</code></pre>

<p>So all you need to do is </p>

<pre class="lang-php prettyprint-override"><code>$order-&gt;markAsComplete();
</code></pre>

<p>Which does </p>

<pre class="lang-PHP prettyprint-override"><code>$this-&gt;isCompleted = true;
$this-&gt;dateOrdered = Db::prepareDateForDb(new \DateTime());
$this-&gt;reference = 'xxxx';
$this-&gt;orderStatusId = y;
</code></pre>

<p>You need to set the 4 parameters above to complete an order correctly, not just the <code>isComplete</code></p>

CC BY-SA 4.0
2019-03-04T15:26:17.177Z
2019-03-04T15:26:17.177Z
Robin Schambach
<p>How do I mark a cart as complete from a plugin?
I tried setting isComplete = 1, it gets moved to orders but it is still a cart.</p>

<craft3><plugin-craftcommerce2>
Mark a cart as complete from a plugin
# Mark a cart as complete from a plugin

(Asked by: username_0 on 2019-03-04)

How do I mark a cart as complete from a plugin?
I tried setting isComplete = 1, it gets moved to orders but it is still a cart.

**Tags:** craft3, plugin-craftcommerce2

---

## 1 answers

### Answer by username_1 on 2019-03-04. Score: 2

When you take a look at the BookingsController you can see exactly what happens when you need to mark an order as complete
public function actionCompleteOrder(): Response
{
    $this->requireAcceptsJson();
    $orderId = Craft::$app->getRequest()->getParam('orderId');

    $order = Plugin::getInstance()->getOrders()->getOrderById($orderId);

    if ($order && !$order->isCompleted && $order->markAsComplete()) {
        $date = new \DateTime($order->dateOrdered);
        return $this->asJson(['success' => true, 'dateOrdered' => $date]);
    }

    return $this->asErrorJson(Craft::t('commerce', 'Could not mark the order as completed.'));
}

So all you need to do is 
$order->markAsComplete();

Which does 
$this->isCompleted = true;
$this->dateOrdered = Db::prepareDateForDb(new \DateTime());
$this->reference = 'xxxx';
$this->orderStatusId = y;

You need to set the 4 parameters above to complete an order correctly, not just the isComplete


---

