0

I am struggling to get an order to be marked as completed in Drupal 7 Commerce.

Customers will go through the checkout process inside of Drupal, gets marked as "Awaiting shipment" (a custom order status), but then a fulfillment team goes through a different program and the order should be getting updated programmatically as "Completed".

However, when I use commerce_order_status_update it doesn't seem to want to get marked as completed.

Here is the code I am working with:

$order_entity = commerce_order_load($orderId); 
commerce_order_status_update($order_entity, 'completed', false, true, 'Order updated via warehouse');
watchdog('warehouse', 'Order status updated %o', array('%o' => $order_entity->status)); //Does not equal 'completed'

I know this code is firing because of two reasons:

  1. When I set 'completed' to be different status messages, it works
  2. I see the revision message "Order updated via warehouse", but the status has not changed.

Is there something I have missed? Am I marking the order as completed in a wrong way?

I have also tried EMW

$order_wrapper = entity_metadata_wrapper('commerce_order', commerce_order_load($orderId));
$order_wrapper->status->set('completed');
watchdog('warehouse', 'Order status updated %o', array('%o' => $order_wrapper_status->value())); // Does not update to 'completed'
$order_wrapper->save();

EDIT
I added the watchdog statements that I have used to echo out of the operation was successful.
It should also be noted that there are no Rules modifying the order status at this point. I have gone through my list of Rules and verified that nothing is modifying it, and the order history shows no new revision created from Rules.

Error logs also show no error happening on save process. The operation is successful if I change 'completed' to any other status.

  • 1
    There is rule that fires on order status change. What does it say? You could turn debugging options on in Rules settings to see the log. – AltaGrade Mar 26 '18 at 6:58
  • 1
    If the status isn't updating as you'd expect, you need to look for one of two things: an error in the save process that prevents the change from being saved to the database or code that executes after that update to set the status back to something else. Without further information, there isn't much we can do to help. – Ryan Szrama Mar 26 '18 at 13:07
  • 1
    @RyanSzrama You are absolutely right. I have added more information that I hope is useful. I have updated the question to include information about rules and additional debug steps. – loganfarr Mar 26 '18 at 15:35
1

I figured this issue out.

I had a Rule that was firing "before a commerce order was saved" that reset the order status but did not show any errors or log any thing. Not sure why that rule wsn't working correctly, but now that I have disabled it, the status is updating successfully.

  • 1
    hehe, glad to hear it. I should've put my comment in an answer to get the karma. : P – Ryan Szrama Mar 27 '18 at 16:08

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.