You are here

function uc_product_title_sku_autocomplete in Ubercart 6.2

Returns an autocomplete list for product nodes.

Using this autocomplete on a textfield will autocomplete based on product titles or SKUs and leave the nid in the textfield.

1 string reference to 'uc_product_title_sku_autocomplete'
uc_product_menu in uc_product/uc_product.module
Implements hook_menu().

File

uc_product/uc_product.pages.inc, line 14
Defines page callbacks for the product module.

Code

function uc_product_title_sku_autocomplete($string = '') {
  $matches = array();
  if ($string) {
    $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, p.model, p.unique_hash FROM {uc_products} AS p LEFT JOIN {node} AS n ON n.nid = p.nid WHERE p.unique_hash <> '' AND (LOWER(n.title) LIKE '%s%%' OR LOWER(p.model) LIKE '%s%%')"), strtolower($string), strtolower($string), 0, 10);
    while ($node = db_fetch_object($result)) {
      $matches[$node->nid] = t('@title [@sku]', array(
        '@title' => $node->title,
        '@sku' => $node->model,
      ));
    }
  }
  drupal_json($matches);
}