1. commerce
    1. 7
7 commerce_product_match_products($field, $instance = NULL, $string = '', $match = 'contains', $ids = array(), $limit = NULL, $access_tag = FALSE)

Fetches an array of all products matching the given parameters.

This info is used in various places (allowed values, autocomplete results, input validation...). Some of them only need the product_ids, others product_id + titles, others yet product_id + titles + rendered row (for display in widgets).

The array we return contains all the potentially needed information, and lets calling functions use the parts they actually need.


$field The field description.

$string Optional string to filter SKUs and titles on (used by autocomplete).

$match Operator to match filtered SKUs and titles against, can be any of: 'contains', 'equals', 'starts_with'

$ids Optional product ids to lookup (used when $string and $match arguments are not given).

$limit If non-zero, limit the size of the result set.

$access_tag Boolean indicating whether or not an access control tag should be added to the query to find matching product data. Defaults to FALSE.

Return value

An array of valid products in the form: array( product_id => array( 'product_sku' => The product SKU, 'title' => The product title, 'rendered' => The text to display in widgets (can be HTML) ), ... )


modules/product/commerce_product.module, line 782

function commerce_product_match_products($field, $instance = NULL, $string = '', $match = 'contains', $ids = array(), $limit = NULL, $access_tag = FALSE) {
  $results = &drupal_static(__FUNCTION__, array());

  // Create unique id for static cache.
  $cid = implode(':', array(
    ($string !== '' ? $string : implode('-', $ids)),

  if (!isset($results[$cid])) {
    $matches = _commerce_product_match_products_standard($instance, $string, $match, $ids, $limit, $access_tag);

    // Store the results.
    $results[$cid] = !empty($matches) ? $matches : array();

  return $results[$cid];