1
Answers
Vote up!
0
Vote down!

Can the order_number differ from the order_id? If so, why is my add to cart failing?

UPDATE: I tried Add to Cart several times while attempting to figure this out, and suddenly it started working. I'm still curious about what went wrong, because it would give me more confidence in my migration, but, oh, well...

I just used Commerce Migrate Ubercart to bring the data from our D6 Ubercart store into Commerce. In the commerce_order table in the database, I see that the order_id's are different from the order_number's (e.g., order_id 1 has the order_number 97). The highest order_id in the database is 597. The highest order_number is 718. I just tried to add an item to my cart for the first time since the migration, and I got the following error:


PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '598' for key 'order_number':
UPDATE {commerce_order} SET order_number=:db_update_placeholder_0 WHERE (order_id = :db_condition_placeholder_0) ;
Array ( [:db_update_placeholder_0] => 598 [:db_condition_placeholder_0] => 598 )
in commerce_order_commerce_order_insert()
(line 870 of /Applications/MAMP/htdocs/seven/sites/all/modules/commerce/modules/order/commerce_order.module).

Line 870 is the first execute() in the code excerpt here:

/**
* Implements hook_commerce_order_insert().
*/
function commerce_order_commerce_order_insert($order) {
  // Save the order number.
  // TODO: Provide token support for order number patterns.

  if (empty($order->order_number)) {
    $order->order_number = $order->order_id;

    db_update('commerce_order')
      ->fields(array('order_number' => $order->order_number))
      ->condition('order_id', $order->order_id)
      ->execute();
    db_update('commerce_order_revision')
      ->fields(array('order_number' => $order->order_number))
      ->condition('order_id', $order->order_id)
      ->execute();
  }
}

The lines

if (empty($order->order_number)) {
    $order->order_number = $order->order_id;

would seem to imply that the default is for them to be the same, but it is possible for them to differ. There is a function commerce_order_validate_number_unique($order_number, $order_id), but I don't see it getting called anywhere within the entire Commerce module (based on "grep -r commerce_order_validate_number_unique ." in the commerce directory.)

Basically, I don't understand what's going wrong in my case.

Asked by: erica
on August 15, 2012

1 Answer