Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save colepacak/e5f5ad52a588afdf815e6380c1c110ca to your computer and use it in GitHub Desktop.
Save colepacak/e5f5ad52a588afdf815e6380c1c110ca to your computer and use it in GitHub Desktop.
Add contact name to invoice
diff --git a/modules/commerce_billy_pdf/commerce_billy_pdf.module b/modules/commerce_billy_pdf/commerce_billy_pdf.module
index 8af41b0..abe546d 100644
--- a/modules/commerce_billy_pdf/commerce_billy_pdf.module
+++ b/modules/commerce_billy_pdf/commerce_billy_pdf.module
@@ -200,6 +200,22 @@ function commerce_billy_pdf_commerce_order_view($order, $view_mode) {
$order->content['invoice_logo'] = array(
'#value' => variable_get('commerce_billy_pdf_logo', 'misc/druplicon.png'),
);
+ // Get civicrm contact off of membership line item
+ $line_items = $order->commerce_line_items;
+ foreach ($line_items['und'] as $key => $value) {
+ $line_item = commerce_line_item_load($value['line_item_id']);
+ if ($line_item->type === 'membership') {
+ civicrm_initialize();
+ $contact_result = civicrm_api('contact', 'get', array(
+ 'version' => 3,
+ 'id' => $line_item->field_civicrm_contact['und'][0]['contact_id'],
+ ));
+ $contact = reset($contact_result['values']);
+ $order->content['contact_name'] = array(
+ '#markup' => t('Name: ' . $contact['display_name']),
+ );
+ }
+ }
}
}
diff --git a/modules/commerce_billy_pdf/templates/commerce_order--commerce_order--pdf.tpl.php b/modules/commerce_billy_pdf/templates/commerce_order--commerce_order--pdf.tpl.php
index a9f13e1..946fa94 100644
--- a/modules/commerce_billy_pdf/templates/commerce_order--commerce_order--pdf.tpl.php
+++ b/modules/commerce_billy_pdf/templates/commerce_order--commerce_order--pdf.tpl.php
@@ -22,6 +22,10 @@
<div class="invoice-number"><?php print render($content['order_number']); ?></div>
<div class="order-id"><?php print render($content['order_id']); ?></div>
+ <?php if (!empty($content['contact_name'])): ?>
+ <div class="contact-name"><?php print render($content['contact_name']); ?></div>
+ <?php endif; ?>
+
<div class="line-items">
<div class="line-items-view"><?php print render($content['commerce_line_items']); ?></div>
<div class="order-total"><?php print render($content['commerce_order_total']); ?></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment