function commerce_product_reference_default_product in Commerce Core 7
Returns the default referenced product from an array of product entities.
The basic behavior for determining a default product from an array of referenced products is to use the first referenced product. This function also allows other modules to specify a different default product through hook_commerce_product_reference_default_delta_alter().
Parameters
$products: An array of product entities referenced by a product reference field.
Return value
The default product entity.
2 calls to commerce_product_reference_default_product()
- commerce_cart_field_formatter_view in modules/
cart/ commerce_cart.module - Implements hook_field_formatter_view().
- commerce_product_reference_entity_view in modules/
product_reference/ commerce_product_reference.module - Implements hook_entity_view().
File
- modules/
product_reference/ commerce_product_reference.module, line 1558 - Defines a field type for referencing products from other entities.
Code
function commerce_product_reference_default_product($products) {
// Fetch the first delta value from the array.
reset($products);
$delta = key($products);
// Allow other modules to specify a different delta value if desired.
drupal_alter('commerce_product_reference_default_delta', $delta, $products);
return $products[$delta];
}