I’m trying to change the order_number after the order has been created. Specifically, I need to do this in the hook_commerce_checkout_complete
or hook_commerce_payment_order_paid_in_full
functions.
I’m sending orders out for 3rd party fulfillment and want to store the 3rd party’s unique order_number (which is different than Drupal Commerce’s order_number) into DC’s order_number column.
I do not need to change the order_number in hook_commerce_order_presave
because this happens before I make the call to 3rd party fulfillment when the new order_number gets generated in their system.
You can see in the code below that this is being executed as the order is paid in full, during checkout completion. In this example the order_number 00001890 is trying to be changed to 9999999 and saved, but the new order_number is not actually saving.
function custom_module_commerce_payment_order_paid_in_full($transaction) { print "<pre>"; print "paid in fulln"; print_r($transaction); $orderid = $transaction->order_id; $order = commerce_order_load($orderid); print "BEFORE CHANGING ORDER NUMBER n"; //order number is 00001890 print_r($order); $order->order_number = 9999999; print "AFTER CHANGING ORDER NUMBER n"; //order number is 9999999 print_r($order); $result = commerce_order_save($order); print "Order save resultn"; //SAVED_UPDATED = 2 print_r($result); print "DID ORDER NUMBER CHANGE??? n"; //no, it did not change, it's still 00001890 print_r($order); $order = commerce_order_load($orderid); //confirm order number did not change, it's still 00001890 print_r($order); print "</pre>"; die(); }
Any help or advice would be much appreciated!
Sponsored by SupremePR