You are here

function commerce_gc_handler_area_balance_summary::render in Commerce GC 7

Render the area.

Overrides views_handler_area::render

File

includes/views/handlers/commerce_gc_handler_area_balance_summary.inc, line 9
Provides a transaction balance area for a giftcard coupon

Class

commerce_gc_handler_area_balance_summary
@file Provides a transaction balance area for a giftcard coupon

Code

function render($empty = FALSE) {
  if (!$empty || !empty($this->options['empty'])) {
    foreach ($this->view->argument as $name => $argument) {
      if (count($argument->value) == 1) {
        $value = reset($argument->value);

        // Find some kind of argument we can use.
        if ($argument instanceof commerce_coupon_handler_argument_coupon_code) {
          $coupon = commerce_coupon_load_by_code($value);
        }
        else {
          if ($argument instanceof commerce_coupon_handler_argument_coupon_id) {
            $coupon = commerce_coupon_load($value);
          }
        }
        if ($coupon) {
          $balance = commerce_gc_giftcard_balance($coupon->coupon_id);
          return '<div class="commerce-order-handler-area-order-total">' . t('Balance') . ': ' . commerce_currency_format($balance, commerce_default_currency()) . '</div>';
        }
      }
    }
  }
  return '';
}