1

Is there a way to edit an orders status via a frontend template?

2

A customer can not update the order status from the front end. Only a user in the CP with the right permissions can do so from the Edit Order page.

To add this functionality you would need to make your own controller action endpoint (in a plugin or module) that does the following:

<?php

namespace modules\mymodule\controllers;

use modules\mymodule\MyModule;

use Craft;
use craft\web\Controller;

/**
 * @author    You
 * @package   MyModule
 * @since     1.0.0
 */
class UpdateOrderStatusController extends Controller
{
    protected $allowAnonymous = ['index'];

    /**
     * @return mixed
     */
    public function actionIndex()
    {
        $this->requirePostRequest();
        $this->requireAcceptsJson()
        // validate the current user is allowed to edit the order?

        Craft::$app->getRequest()->getParam('purchasableId')
        $order = Order::find()->id(ID_FROM_REQUEST_HERE)->one();

        if($order){
          $order->orderStatusId = $this->orderStatusId;
          $order->message = $this->message;
          Craft::$app->getElements()->saveElement($order, false);
          return $this->asJson([
              'errors' => $order->getErrors(),
              'success' => !$order->hasErrors(),
          ]);
        }

        return $this->asJson([
            'errors' => ['No order found'],
            'success' => false,
        ]);
    }
}

| improve this answer | |

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.