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.


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


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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