1. commerce
    1. 7
7 commerce_product_validate_sku_unique($sku, $product_id)

Checks to see if a given SKU already exists for another product.


$sku The string to match against existing SKUs.

$product_id The ID of the product the SKU is for; an empty value represents the SKU is meant for a new product.

Return value

TRUE or FALSE indicating whether or not the SKU exists for another product.


modules/product/commerce_product.module, line 655

function commerce_product_validate_sku_unique($sku, $product_id) {
  // Look for an ID of a product matching the supplied SKU.
  if ($match_id = db_query('SELECT product_id FROM {commerce_product} WHERE sku = :sku', array(':sku' => $sku))->fetchField()) {
    // If this SKU is supposed to be for a new product or a product other than
    // the one that matched...
    if (empty($product_id) || $match_id != $product_id) {
      return FALSE;

  return TRUE;