function _commerce_price_get_price_fields in Commerce Core 7
Returns an array of commerce_price field names from a specific entity.
Parameters
$entity_type: The entity type variable passed through hook_field_storage_pre_*() or hook_field_attach_*().
$entity: The entity variable passed through hook_field_storage_pre_*() or hook_field_attach_*().
Return value
array An array of commerce_price field names or an empty array if none are found.
2 calls to _commerce_price_get_price_fields()
- _commerce_price_field_serialize_data in modules/
price/ commerce_price.module - Converts price field data to a serialized array.
- _commerce_price_field_unserialize_data in modules/
price/ commerce_price.module - Converts saved price field data columns back to arrays for use in the rest of the current page request execution.
File
- modules/
price/ commerce_price.module, line 113 - Defines the Price field with widgets and formatters used to add prices with currency codes to various Commerce entities.
Code
function _commerce_price_get_price_fields($entity_type, $entity) {
$commerce_price_fields = array();
// Determine the list of instances to iterate on.
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
$instances = field_info_instances($entity_type, $bundle);
// Iterate through the instances and collect results.
foreach ($instances as $instance) {
$field_name = $instance['field_name'];
$field = field_info_field($field_name);
// If the instance is a price field with data...
if ($field['type'] == 'commerce_price' && isset($entity->{$field_name})) {
$commerce_price_fields[] = $field_name;
}
}
return $commerce_price_fields;
}