You are here

function commerce_order_validate_number_unique in Commerce Core 7

Checks to see if a given order number already exists for another order.

Parameters

$order_number: The string to match against existing order numbers.

$order_id: The ID of the order the number is for; an empty value represents the number is meant for a new order.

Return value

TRUE or FALSE indicating whether or not the number exists for another order.

File

modules/order/commerce_order.module, line 984
Defines the core Commerce order entity and API functions to manage orders and interact with them.

Code

function commerce_order_validate_number_unique($order_number, $order_id) {

  // Look for an ID of an order matching the supplied number.
  if ($match_id = db_query('SELECT order_id FROM {commerce_order} WHERE order_number = :order_number', array(
    ':order_number' => $order_number,
  ))
    ->fetchField()) {

    // If this number is supposed to be for a new order or an order other than
    // the one that matched...
    if (empty($order_id) || $match_id != $order_id) {
      return FALSE;
    }
  }
  return TRUE;
}