You are here

function uc_product_get_models in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_product/uc_product.module \uc_product_get_models()
  2. 6.2 uc_product/uc_product.module \uc_product_get_models()

Gets all models of a product (node).

Gathers any modules' models on this node, then add the node's SKU and the optional 'Any' option.

Parameters

$nid: The node ID of the product.

$add_blank: String to use for the initial blank entry. If not desired, set to NULL or FALSE. Make sure to localize the string first. Defaults to '- Any -'.

Return value

An associative array of model numbers. The key for '- Any -' is the empty string.

4 calls to uc_product_get_models()
uc_file_feature_form in uc_file/uc_file.module
Form builder for hook_uc_product_feature.
uc_order_condition_has_products_options in uc_order/uc_order.rules.inc
Options callback.
uc_roles_feature_form in uc_roles/uc_roles.module
Form builder for hook_uc_product_feature().
uc_stock_edit_form in uc_stock/uc_stock.admin.inc
Form builder for product stock edit form.

File

uc_product/uc_product.module, line 1349
The product module for Ubercart.

Code

function uc_product_get_models($nid, $add_blank = TRUE) {

  // Get any modules' SKUs on this node.
  $models = module_invoke_all('uc_product_models', $nid);

  // Add the base SKU of the node.
  $models[] = db_query('SELECT model FROM {uc_products} WHERE nid = :nid', array(
    ':nid' => $nid,
  ))
    ->fetchField();

  // Now we map the SKUs to the keys, for form handling, etc.
  $models = drupal_map_assoc($models);

  // Sort the SKUs.
  asort($models);

  // And finally, we prepend 'Any' so it's the first option.
  if (!empty($add_blank) || $add_blank === '') {
    if ($add_blank === TRUE) {
      $add_blank = t('- Any -');
    }
    return array(
      '' => $add_blank,
    ) + $models;
  }
  return $models;
}