From: Steve Sutton Date: Fri, 2 Dec 2016 15:50:09 +0000 (-0500) Subject: Working on the email notifications X-Git-Tag: v1.0.0^2~13 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=ec42b98693a446966b1d03704b462a201d6ff423;p=WP-Plugins%2Fglm-member-db-coupons.git Working on the email notifications Testing owner email --- diff --git a/classes/helper/notification.php b/classes/helper/notification.php index 1012324..1d99fa6 100644 --- a/classes/helper/notification.php +++ b/classes/helper/notification.php @@ -77,9 +77,55 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers /** * Send the member a notice */ - public function sendMemberNotice() + public function sendMemberNotice( $memberId, $coupon ) { + $member = $this->getEntry( $memberId ); + // find notify_to + // This will be the primary contact email if found + // if not found use the member info record email + // if nothing in either one then return. + $settings = $this->config['settings']; + $notify_from = $settings['notify_from']; + + // Setup the Smarty Engine + $smarty = new smartyTemplateSupport(); + $viewPath = GLM_MEMBERS_COUPONS_PLUGIN_PATH . '/views'; + $smarty->template->setTemplateDir( $viewPath ); + + // Add standard parameters + require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; + $viewFile = 'front/coupons/ownerEmail.html'; + + $couponList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-coupons-list"; + $smarty->templateAssign( 'notify_message', $notify_message); + $smarty->templateAssign( 'location', 'Member Coupons' ); + $smarty->templateAssign( 'name', $coupon['fieldData']['name'] ); + $smarty->templateAssign( 'pendingCoupons', $couponList ); + // Generate output from model data and view + $htmlMessage = $smarty->template->fetch( $viewFile ); + + + // 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' ) ); + + $subject = 'Coupon Form Submission'; + $message = $htmlMessage; + $header[] = 'From:' . $notify_from; + $header[] = 'Reply-To:' . $notify_from; + + wp_mail( $notify_to, $subject, $message, $header ); + + // remove the filter to avoid conflicts + remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); } /** @@ -87,36 +133,40 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers */ public function sendAdminNotice( $memberId, $coupon ) { - $member = $this->getEntry( $memberId ); + $member = $this->getEntry( $memberId ); $settings = $this->config['settings']; $notify_to = $settings['notify_to']; $notify_from = $settings['notify_from']; $notify_message = $settings['notify_message']; // Setup the Smarty Engine - $smarty = new smartyTemplateSupport(); + $smarty = new smartyTemplateSupport(); $viewPath = GLM_MEMBERS_COUPONS_PLUGIN_PATH . '/views'; - $smarty->template->setTemplateDir($viewPath); + $smarty->template->setTemplateDir( $viewPath ); // Add standard parameters require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; - $viewFile = 'front/coupons/ownerEmail.html'; - - $smarty->templateAssign('notify_message', $notify_message); - $smarty->templateAssign('name', $coupon['fieldData']['name']); - $smarty->templateAssign('start_date', $coupon['fieldData']['start_date']); - $smarty->templateAssign('end_date', $coupon['fieldData']['end_date']); - $smarty->templateAssign('expire', $coupon['fieldData']['expire']); + $viewFile = 'front/coupons/ownerEmail.html'; + + $couponList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-coupons-list"; + $smarty->templateAssign( 'notify_message', $notify_message); + $smarty->templateAssign( 'location', 'Member Coupons' ); + $smarty->templateAssign( 'member', $member ); + $smarty->templateAssign( 'name', $coupon['fieldData']['name'] ); + $smarty->templateAssign( 'start_date', $coupon['fieldData']['start_date'] ); + $smarty->templateAssign( 'end_date', $coupon['fieldData']['end_date'] ); + $smarty->templateAssign( 'expire', $coupon['fieldData']['expire'] ); + $smarty->templateAssign( 'pendingCoupons', $couponList ); // Generate output from model data and view - $htmlMessage = $smarty->template->fetch($viewFile); + $htmlMessage = $smarty->template->fetch( $viewFile ); // change the default wordpress from name when sending mail add_filter( 'wp_mail_from_name', - function ($name) { - $siteName = get_bloginfo('name'); + function ( $name ) { + $siteName = get_bloginfo( 'name' ); return $siteName; } ); diff --git a/models/admin/coupons/list.php b/models/admin/coupons/list.php index 8e5572a..05276e7 100644 --- a/models/admin/coupons/list.php +++ b/models/admin/coupons/list.php @@ -299,6 +299,8 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons // Update approved timestamp. $this->updateTimestamp('approved', $this->couponID); } else if ( $lockedToMember && $old_coupon_status == 10 && $new_status == 20 ) { + // Here the status is changing from active to pending. (member edit) + // Send notice to admin user if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest']) ) { $notification->sendAdminNotice( $member_id, $coupon); } diff --git a/views/front/coupons/ownerEmail.html b/views/front/coupons/ownerEmail.html index 1ab995b..f591448 100644 --- a/views/front/coupons/ownerEmail.html +++ b/views/front/coupons/ownerEmail.html @@ -13,21 +13,25 @@ {/if} + + + + - + - + - +
Member Name:{$member.name}
Coupon Name: {$name}
Coupon Start Date: {$start_date} {$start_date.timestamp|date_format:"%D"}
Coupon End Date:{$end_date}{$end_date.timestamp|date_format:"%D"}
Coupon Expire Date:{$expire}{$expire.timestamp|date_format:"%D"}