1

I am using this simple code:

$order = commerce_order_load($order_id);
$order->status='completed';
field_attach_update('commerce_order', $order);

To update the status of order to completed.

This code use to work but does not work anymore (the order status is not updated).

How to debug this ?

UPDATE:

Using :

entity_get_controller('commerce_order')->resetCache(array($order->order_id));

Does not work neither.

1 Answer 1

1

You can't debug what ain't a bug :)

status is a property, not a field, of the commerce_order entity type - so it isn't affected by running field_attach_update(), which just saves field data, and avoids saving the entity itself.

You'll need to use commerce_order_save(), entity_save(), or manipulate the commerce_order table directly, and then clear the cache using the entity controller.

3
  • 1
    You beat me to it ;) Commented May 18, 2016 at 14:52
  • @Clive how is that this worked previously ? Commented May 18, 2016 at 15:00
  • I'm not really sure how to answer that - according to the code, it didn't.
    – Clive
    Commented May 18, 2016 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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