function uc_product_get_models in Ubercart 6.2
Same name and namespace in other branches
- 8.4 uc_product/uc_product.module \uc_product_get_models()
- 7.3 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_product_feature.
- uc_order_condition_has_products_form in uc_order/
uc_order.ca.inc - uc_roles_feature_form in uc_roles/
uc_roles.module - Form builder for hook_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 1697 - The product module for Ubercart.
Code
function uc_product_get_models($nid, $add_blank = TRUE) {
// Keep backward compatibility with previous versions of 6.x-2.x, where
// first argument was a product object.
if (is_object($nid)) {
$nid = $nid->nid;
}
// Get any modules' SKUs on this node.
$models = module_invoke_all('uc_product_models', $nid);
// Add the base SKU of the node.
$models[] = db_result(db_query("SELECT model FROM {uc_products} WHERE nid = %d", $nid));
// 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;
}