function commerce_product_reference_commerce_product_uri in Commerce Core 7
Implements hook_commerce_product_uri().
File
- modules/
product_reference/ commerce_product_reference.module, line 12 - Defines a field type for referencing products from other entities.
Code
function commerce_product_reference_commerce_product_uri($product) {
// If the product has a display context, use its URI.
if (!empty($product->display_context)) {
// If the display context does not have the fully loaded entity, as on the
// Add to Cart form refresh, load it now using the entity ID if present.
if (empty($product->display_context['entity']) && !empty($product->display_context['entity_id'])) {
$product->display_context['entity'] = entity_load_single($product->display_context['entity_type'], $product->display_context['entity_id']);
}
// Do not return a URI without a valid entity type or loaded entity.
if (empty($product->display_context['entity_type']) || empty($product->display_context['entity'])) {
// Otherwise do not return a URI from this function.
return NULL;
}
return entity_uri($product->display_context['entity_type'], $product->display_context['entity']);
}
}