From 95541a18ee9b2668ba7d51fe972a67122f2c3592 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 10 Jan 2018 16:48:46 -0500 Subject: [PATCH] WIP billing notifications working on the merge stuff. Grabbing the functions from registrations. --- classes/notifications.php | 60 +++++++++++++++++-- models/admin/settings/notificationTypes.php | 8 +-- .../admin/settings/editNotificationType.html | 43 +++++++++++++ 3 files changed, 102 insertions(+), 9 deletions(-) diff --git a/classes/notifications.php b/classes/notifications.php index 7baacb6..afe1f12 100644 --- a/classes/notifications.php +++ b/classes/notifications.php @@ -78,6 +78,8 @@ class GlmNotifications // If there's no account then return false. return false; } + // echo '
$account: ' . print_r( $account, true ) . '
'; + // exit; $to_email = $account['email']; if ( !$to_email ) { // If there's no email then return false. @@ -87,12 +89,12 @@ class GlmNotifications // get the Notification type var_dump( $notification_id ); $notification_type = $this->getNotificationTypeById( $notification_id ); - echo '
$notification_type: ' . print_r( $notification_type, true ) . '
'; + // echo '
$notification_type: ' . print_r( $notification_type, true ) . '
'; if ( !$notification_type ) { // If there's no notification type then return false. return false; } - $subject = $notification_type['subject']; + $subject = $notification_type['subject']; if ( !$subject ) { // If there's no subject then return false. return false; @@ -107,10 +109,31 @@ class GlmNotifications // Add standard parameters require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; - $viewFile = 'admin/notifications/notification.html'; + $viewFile = 'admin/notifications/notification.html'; + + $account_data = array( + 'account' => array( + 'name' => $account['ref_name'], + 'email' => $account['email'], + 'addr1' => $account['billing_addr1'], + 'addr2' => $account['billing_addr2'], + 'city' => $account['billing_city'], + 'state' => $account['billing_state'], + 'zip' => $account['billing_zip'], + 'phone' => $account['billing_phone'], + ) + ); + echo '
$notification_type[message]: ' . print_r( $notification_type['message'], true ) . '
'; + $notification_message = $this->parseSmartyTemplateString( + $account_data, + wpautop( $notification_type['message'] ) + ); + echo '
$account_data: ' . print_r( $account_data, true ) . '
'; + echo '
$notification_message: ' . print_r( $notification_message, true ) . '
'; + // exit; $smarty->templateAssign( 'title', $notification_type['subject'] ); - $smarty->templateAssign( 'html_content', wpautop( $notification_type['message'] ) ); + $smarty->templateAssign( 'html_content', $notification_message ); // Generate output from model data and view $htmlMessage = $smarty->template->fetch( $viewFile ); @@ -148,6 +171,25 @@ class GlmNotifications $this->recordNotification( $notice_data ); } + public function parseSmartyTemplateString( $data, $template_string ) + { + // Load Smarty Template support + $smarty = new smartyTemplateSupport(); + + // Add standard parameters + require GLM_MEMBERS_PLUGIN_SETUP_PATH . '/standardTemplateParams.php'; + + // Add data from model to Smarty template + if ( is_array( $data ) && count( $data ) > 0 ) { + foreach ( $data as $key => $value ) { + echo '
$key: ' . print_r( $key, true ) . '
'; + $smarty->templateAssign( $key, $value ); + } + } + + return $smarty->template->fetch( 'eval:' . $template_string ); + } + /** * recordNotification * @@ -190,7 +232,15 @@ class GlmNotifications return true; } - public function getNotificationByType( $type ) + /** + * getNotificationsByType + * + * @param mixed $type Type of send_action (10: Create Invoice, 20: Received Payment) + * + * @access public + * @return void + */ + public function getNotificationsByType( $type ) { echo '
$this->config: ' . print_r( $this->config['send_action_numb'], true ) . '
'; return $this->wpdb->get_results( diff --git a/models/admin/settings/notificationTypes.php b/models/admin/settings/notificationTypes.php index 2032b58..e4a3e63 100644 --- a/models/admin/settings/notificationTypes.php +++ b/models/admin/settings/notificationTypes.php @@ -143,7 +143,9 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType } switch( $option ) { - case 'test': + case 'test': // TODO: remove this case (only for testing notifications) + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php'; + $Notifications = new GlmNotifications( $this->wpdb, $this->config ); /** * test: * @@ -152,10 +154,8 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType * After the test it will call wp_die */ // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; - // require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php'; - // $Notifications = new GlmNotifications( $this->wpdb, $this->config ); // // Test - // $notices = $Notifications->getNotificationByType( 'Create Invoice' ); + // $notices = $Notifications->getNotificationsByType( 'Create Invoice' ); // echo '
$notices: ' . print_r( $notices, true ) . '
'; // if ( $notices ) { // foreach ( $notices as $notice ) { diff --git a/views/admin/settings/editNotificationType.html b/views/admin/settings/editNotificationType.html index 305975a..59154e0 100644 --- a/views/admin/settings/editNotificationType.html +++ b/views/admin/settings/editNotificationType.html @@ -110,6 +110,49 @@ + + +

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.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
+ + + -- 2.17.1