function commerce_price_components_field_formatter_view in Commerce price by components 7
Implements hook_field_formatter_view().
File
- ./
commerce_price_components.module, line 74 - Module file for Price by components.
Code
function commerce_price_components_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
if ($display['type'] == 'commerce_price_components') {
foreach ($items as $delta => $item) {
$price = $item;
$components = $item['data']['components'];
foreach ($components as $key => $component) {
if (!isset($display['settings']['commerce_price_components'][$component['name']]) || !$display['settings']['commerce_price_components'][$component['name']]) {
unset($components[$key]);
}
}
$price['data']['components'] = $components;
$total = commerce_price_component_total($price);
}
}
$element[] = array(
'#markup' => commerce_currency_format($total['amount'], $item['currency_code'], $entity),
);
return $element;
}