You are here

function commerce_gc_product_giftcard_email_variables in Commerce GC 7

File

modules/commerce_gc_product/commerce_gc_product.rules.inc, line 139
Provides Rules module support for buying giftcards.

Code

function commerce_gc_product_giftcard_email_variables(EntityDrupalWrapper $line_item_wrapper) {
  $mail = '';

  // Find a suitable email.
  if (field_info_instance('commerce_line_item', 'commerce_gc_mail', $line_item_wrapper->type
    ->value()) && $line_item_wrapper->commerce_gc_mail
    ->value()) {
    $mail = $line_item_wrapper->commerce_gc_mail
      ->value();
  }
  else {
    if ($line_item_wrapper->order
      ->value() && $line_item_wrapper->order->mail
      ->value()) {
      $mail = $line_item_wrapper->order->mail
        ->value();
    }
    else {
      global $user;
      if ($user->uid) {
        $mail = $user->mail;
      }
    }
  }
  return array(
    'giftcard_mail' => $mail,
  );
}