1

I have a plugin which runs a task on order complete. The tasks runs successfully without any errors. But the problem is the task is only completed when admin is logged in. So if someone has completed the order, they have to wait until an admin logs in to dashboard. What could I be missing? The code I'm using is :

CustomPlugin.php

craft()->on('commerce_orders.onOrderComplete', [$this, 'initializeTask']);

public function initializeTask(Event $event){
    $order = $event->params['order'];
    foreach ($order->lineItems as $lineItem) {
        craft()->tasks->createTask('Custom', null, [
            'id' => $order->id,
        ]);
    }
}

CustomTask.php

class CustomTask extends BaseTask
{
    protected function defineSettings()
    {
        return [
            'id' => AttributeType::Number,
        ];
    }

    public function getDescription()
    {
        return 'Custom Task';
    }

    public function getTotalSteps()
    {
        return 1;
    }

    public function runStep($step)
    {
        $orderId = $this->getSettings()->orderId;
        .
        .
        .
        return true;
    }
}

Is there any type of priority or setting that needs to be set?

1

Got it. Added the following code.

if (!craft()->tasks->isTaskRunning()){
    $task = craft()->tasks->getNextPendingTask();

    if ($task){
        craft()->tasks->runPendingTasks();
    }
}

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.