1

After Payment is accepted, i need to update order status to "Completed" from Controller Page Callback.

How to do this on Drupal 8 Commerce ?

I find no documentation about this, only this example on Drupal 7 :

// Updating Order status.
$orderObj = commerce_order_load($orderID);
commerce_order_status_update($orderObj, 'canceled', TRUE, 'Order Voided');
$orderObj->log = 'Order cancelled programatically';
commerce_order_save($orderObj); 
4

You want to use the State Machine methods of the Commerce Order class.

It would be something like this, but it will depend on what you called your order states.

$order_state = $orderObj->getState();
$order_state_transitions = $order_state->getTransitions();
$order_state->applyTransition($order_state_transitions['complete']);

$orderObj->save();

If you aren't sure, you can always check the $order_state_transitions array to see what options you have.

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.