From: Steve Sutton Date: Thu, 27 Jun 2019 19:14:39 +0000 (-0400) Subject: Adding additional merge tags for the email notifications. X-Git-Tag: v1.0.32^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=7e941494ea97b71810ca99df96c39e8be040a908;p=WP-Plugins%2Fglm-member-db-billing.git Adding additional merge tags for the email notifications. Adding Contacts fields. Adding new billing fields. --- diff --git a/classes/notifications.php b/classes/notifications.php index 5ecf746..f59bf92 100644 --- a/classes/notifications.php +++ b/classes/notifications.php @@ -68,7 +68,7 @@ class GlmNotifications * @access public * @return void */ - public function sendEmailNotification( $notification_id, $account_id, $data = null ) + public function sendEmailNotification( $notification_id, $account_id, $data = null, $test = false ) { // Support Class $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); @@ -79,6 +79,12 @@ class GlmNotifications return false; } + $currentAmount = false; + if ( $account['invoice_type'] ) { + $invTypeData = $BillingSupport->getInvoiceTypeById( $account['invoice_type'] ); + $currentAmount = $invTypeData['amount']; + } + // get the Notification type $notification_type = $this->getNotificationTypeById( $notification_id ); if ( !$notification_type ) { @@ -117,20 +123,44 @@ class GlmNotifications require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; $viewFile = 'admin/notifications/notification.html'; + $contactData = apply_filters( 'glm-member-db-contacts-get-contact-data-by-refdest', $account['ref_dest'] ); + $account_data = array( - 'account' => array( - 'name' => $account['ref_name'], - 'email' => $account['email'], - 'first_name' => $account['billing_fname'], - 'last_name' => $account['billing_lname'], - 'addr1' => $account['billing_addr1'], - 'addr2' => $account['billing_addr2'], - 'city' => $account['billing_city'], - 'state' => $account['billing_state'], - 'zip' => $account['billing_zip'], - 'phone' => $account['billing_phone'], - ) + 'account' => array( + 'name' => $account['ref_name'], + 'email' => $account['email'], + 'first_name' => $account['billing_fname'], + 'last_name' => $account['billing_lname'], + 'addr1' => $account['billing_addr1'], + 'addr2' => $account['billing_addr2'], + 'city' => $account['billing_city'], + 'state' => $account['billing_state'], + 'zip' => $account['billing_zip'], + 'phone' => $account['billing_phone'], + 'company' => $account['billing_company'], + 'position' => $account['billing_position'], + 'renewal_date' => isset( $account['renewal_date'] ) + ? date( 'm/d/Y', strtotime( $account['renewal_date'] ) ) + : '', + 'current_due' => $currentAmount, + ), + 'contact' => array( + 'company' => $contactData['org'], + 'fname' => $contactData['business_fname'], + 'lname' => $contactData['business_lname'], + 'position' => $contactData['title'], + 'addr1' => $contactData['business_addr1'], + 'addr2' => $contactData['business_addr2'], + 'city' => $contactData['business_city'], + 'state' => $contactData['business_state']['value'], + 'email' => $contactData['business_email'], + 'phone' => $contactData['business_phone'], + 'office_phone' => $contactData['office_phone'], + 'mobile_phone' => $contactData['business_mobile'], + 'fax' => $contactData['fax'], + ), ); + echo '
$account_data: ' . print_r( $account_data, true ) . '
'; // Merge any data passed into this method $account_data['data'] = $data; @@ -153,39 +183,45 @@ class GlmNotifications // Generate output from model data and view $htmlMessage = $smarty->template->fetch( $viewFile ); + if ( $test ) { + echo $htmlMessage; + } else { - // change the default wordpress from name when sending mail - add_filter( - 'wp_mail_from_name', - function ( $name ) { - $siteName = get_bloginfo( 'name' ); - return $siteName; + // change the default wordpress from name when sending mail + add_filter( + 'wp_mail_from_name', + function ( $name ) { + $siteName = get_bloginfo( 'name' ); + return $siteName; + } + ); + // Send confirmation email, set the content type to allow html by using this filter + add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); + + $message = $htmlMessage; + $header[] = 'From:' . $from_header; + if ( $replyto ) { + $header[] = 'Reply-To:' . $replyto; } - ); - // Send confirmation email, set the content type to allow html by using this filter - add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); - $message = $htmlMessage; - $header[] = 'From:' . $from_header; - if ( $replyto ) { - $header[] = 'Reply-To:' . $replyto; - } + wp_mail( $to_email, $subject, $message, $header ); - wp_mail( $to_email, $subject, $message, $header ); + // remove the filter to avoid conflicts + remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); - // remove the filter to avoid conflicts - remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); + // Send notification to recordNotification + $notice_data = array( + 'notification_type' => $notification_id, + 'account' => $account_id, + 'from_replyto' => $from_header, + 'subject' => $subject, + 'message' => $message, + 'email_sent' => $to_email, + ); + $this->recordNotification( $notice_data ); + + } - // Send notification to recordNotification - $notice_data = array( - 'notification_type' => $notification_id, - 'account' => $account_id, - 'from_replyto' => $from_header, - 'subject' => $subject, - 'message' => $message, - 'email_sent' => $to_email, - ); - $this->recordNotification( $notice_data ); } /** diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 390a760..29cd5fb 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -196,6 +196,21 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $account_status = apply_filters( 'glm-billing-get-account-status', '', $accountID ); switch ( $option ) { + case 'testNotice': + $view = 'testNotice'; + $Notifications = new GlmNotifications( $this->wpdb, $this->config ); + $accountID = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE ref_dest = %d", + $this->memberID + ) + ); + $Notifications->sendEmailNotification( 17, $accountID, null, true ); + + break; + case 'renew': $view = 'renew'; diff --git a/models/admin/settings/invoiceTypes.php b/models/admin/settings/invoiceTypes.php index f31de07..3832f5d 100644 --- a/models/admin/settings/invoiceTypes.php +++ b/models/admin/settings/invoiceTypes.php @@ -179,6 +179,8 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes ); } + + // Compile template data $templateData = array( 'action' => $_REQUEST['glm_action'], diff --git a/models/admin/settings/notificationTypes.php b/models/admin/settings/notificationTypes.php index b596bd4..706fa2b 100644 --- a/models/admin/settings/notificationTypes.php +++ b/models/admin/settings/notificationTypes.php @@ -242,7 +242,40 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType 'data' => false ); } - + $mergeTagsBilling = array( + 'Name of Account', '{$account.name}', + 'Billing First Name', '{$account.fname}', + 'Billing Last Name', '{$account.lname}', + 'Billing Address Line 1', '{$account.addr1}', + 'Billing Address Line 2', '{$account.addr2}', + 'Billing City', '{$account.city}', + 'Billing State', '{$account.state}', + 'Billing Zip', '{$account.zip}', + 'Billing Email', '{$account.email}', + 'Billing Phone', '{$account.phone}', + 'Billing Company', '{$account.company}', + 'Billing Position', '{$account.position}', + ); + $mergeTagsInvoice = array( + 'Invoice Amount', '{$data.amount}', + ); + $mergeTagsPayment = array( + 'Payment Amount', '{$data.payment}', + ); + $mergeTagsContact = array( + 'Contact First Name', '{$contact.fname}', + 'Contact Last Name', '{$contact.lname}', + 'Contact Address Line 1', '{$contact.addr1}', + 'Contact Address Line 2', '{$contact.addr2}', + 'Contact City', '{$contact.city}', + 'Contact State', '{$contact.state}', + 'Contact Zip', '{$contact.zip}', + 'Contact Company', '{$contact.company}', + 'Contact Position', '{$contact.position}', + 'Contact Email', '{$contact.email}', + 'Contact Phone', '{$contact.office_phone}', + 'Contact Mobile Phone', '{$contact.mobile_phone}', + ); // Compile template data $templateData = array( 'notification_id' => $id, @@ -258,6 +291,10 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType 'send_date_period' => $this->config['send_date_period'], 'send_date_when' => $this->config['send_date_when'], 'send_action' => $this->config['send_action'], + 'mergeTagsBilling' => $mergeTagsBilling, + 'mergeTagsInvoice' => $mergeTagsInvoice, + 'mergeTagsPayment' => $mergeTagsPayment, + 'mergeTagsContact' => $mergeTagsContact, ); // Return status, suggested view, and data to controller diff --git a/views/admin/billing/memberBillingSubHeader.html b/views/admin/billing/memberBillingSubHeader.html index e36a06b..14bbd41 100644 --- a/views/admin/billing/memberBillingSubHeader.html +++ b/views/admin/billing/memberBillingSubHeader.html @@ -32,6 +32,9 @@ href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=makepayment" class="">Pay Invoices +
  • + Test Notices +
  • diff --git a/views/admin/billing/testNotice.html b/views/admin/billing/testNotice.html new file mode 100644 index 0000000..7ea76d9 --- /dev/null +++ b/views/admin/billing/testNotice.html @@ -0,0 +1 @@ +

    Test Notices

    diff --git a/views/admin/settings/editNotificationType.html b/views/admin/settings/editNotificationType.html index 5aa1b6b..26e5080 100644 --- a/views/admin/settings/editNotificationType.html +++ b/views/admin/settings/editNotificationType.html @@ -1,3 +1,8 @@ + {include file='admin/settings/header.html'} {include file='admin/settings/subHeader.html'} @@ -135,67 +140,21 @@ - +

    Merge Tags

    The "merge tags" listed below may be used in the E-Mail message content to include certain information about the Account or Invoice. Be sure to include the "{literal}{{/literal}" and "{literal}}{/literal}" and "$" characters exactly as show.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    {literal}{$account.name}{/literal}Name of Account
    {literal}{$account.first_name}{/literal}Billing First Name
    {literal}{$account.last_name}{/literal}Billing Last Name
    {literal}{$account.addr1}{/literal}Billing Address 1
    {literal}{$account.addr2}{/literal}Billing Address 2
    {literal}{$account.city}{/literal}Billing City
    {literal}{$account.state}{/literal}Billing State
    {literal}{$account.zip}{/literal}Billing Zip
    {literal}{$account.email}{/literal}Billing Email
    {literal}{$account.phone}{/literal}Billing Phone
    Only available using Immediate Action - Create Invoice
    {literal}{$data.amount}{/literal}Invoice Amount
    Only available using Immediate Action - Received Payment
    {literal}{$data.payment}{/literal}Payment Amount
    + + {html_table loop=$mergeTagsBilling cols=2 table_attr='border=0 width=400' caption='Billing Examples'} + + {html_table loop=$mergeTagsContact cols=2 table_attr='border=0 width=400' caption='Contact Examples'} + + {html_table loop=$mergeTagsInvoice cols=2 table_attr='border=0 width=400' caption='Only available using Immediate Action - Create Invoice'} + + {html_table loop=$mergeTagsPayment cols=2 table_attr='border=0 width=400' caption='Only available using Immediate Action - Received Payment'} + +