You are here

function commerce_reports_field_formatter_view in Commerce Reporting 7.3

Same name and namespace in other branches
  1. 7.4 commerce_reports.module \commerce_reports_field_formatter_view()

Implements hook_field_formatter_view().

Executes the formatter view for the commerce price field type.

File

./commerce_reports.module, line 172

Code

function commerce_reports_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $default_currency = commerce_default_currency();
  $element = array();
  foreach ($items as $delta => $item) {
    if (is_null($item['amount'])) {
      continue;
    }
    switch ($display['type']) {
      case 'commerce_reports_visualization':
        if ($item['currency_code'] != $default_currency) {
          $amount = commerce_currency_convert($item['amount'], $item['currency_code'], $default_currency);
        }
        else {
          $amount = $item['amount'];
        }
        $element[$delta] = array(
          '#markup' => commerce_currency_amount_to_decimal($amount, $default_currency),
        );
        break;
    }
  }
  return $element;
}