WIP billing notifications
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 10 Jan 2018 21:48:46 +0000 (16:48 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 10 Jan 2018 21:48:46 +0000 (16:48 -0500)
working on the merge stuff. Grabbing the functions from registrations.

classes/notifications.php
models/admin/settings/notificationTypes.php
views/admin/settings/editNotificationType.html

index 7baacb6..afe1f12 100644 (file)
@@ -78,6 +78,8 @@ class GlmNotifications
             // If there's no account then return false.
             return false;
         }
+        // echo '<pre>$account: ' . print_r( $account, true ) . '</pre>';
+        // 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 '<pre>$notification_type: ' . print_r( $notification_type, true ) . '</pre>';
+        // echo '<pre>$notification_type: ' . print_r( $notification_type, true ) . '</pre>';
         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 '<pre>$notification_type[message]: ' . print_r( $notification_type['message'], true ) . '</pre>';
+        $notification_message = $this->parseSmartyTemplateString(
+            $account_data,
+            wpautop( $notification_type['message'] )
+        );
+        echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
+        echo '<pre>$notification_message: ' . print_r( $notification_message, true ) . '</pre>';
+        // 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 '<pre>$key: ' . print_r( $key, true ) . '</pre>';
+                $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 '<pre>$this->config: ' . print_r( $this->config['send_action_numb'], true ) . '</pre>';
         return $this->wpdb->get_results(
index 2032b58..e4a3e63 100644 (file)
@@ -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 '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
-            // 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 '<pre>$notices: ' . print_r( $notices, true ) . '</pre>';
             // if ( $notices ) {
             //     foreach ( $notices as $notice ) {
index 305975a..59154e0 100644 (file)
             </td>
         </tr>
 
+        <tr>
+            <td colspan="2">
+                <h4>Merge Tags</h4>
+                <p>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.</p>
+                <table>
+                    <tr>
+                        <th>{literal}{$account.name}{/literal}</th>
+                        <td>Name of Account</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$account.addr1}{/literal}</th>
+                        <td>Billing Address 1</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$account.addr2}{/literal}</th>
+                        <td>Billing Address 2</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$account.city}{/literal}</th>
+                        <td>Billing City</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$account.state}{/literal}</th>
+                        <td>Billing State</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$account.zip}{/literal}</th>
+                        <td>Billing Zip</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$account.email}{/literal}</th>
+                        <td>Billing Email</td>
+                    </tr>
+                    <tr>
+                        <th>{literal}{$account.phone}{/literal}</th>
+                        <td>Billing Phone</td>
+                    </tr>
+                </table>
+            </td>
+        </tr>
+
         <tr>
             <td colspan="2">
                 <input class="button button-primary" type="submit" value="{if $notification_id}Update{else}Add{/if} Notification Type">