فهرست منبع

Email alert on lab results report ready

Samson Mutunga 2 ماه پیش
والد
کامیت
b35130770a

+ 6 - 5
app/Http/Controllers/AdminController.php

@@ -568,7 +568,8 @@ class AdminController extends Controller
     $order->save();
 
     if($fileRef === 'results_attachment'){
-        $this->emailReport($request, $order);
+        //$this->emailReport($request, $order);
+        $this->emailService->emailOrderReportReadyAlert($order);
     }
 
     return $this->pass();
@@ -595,20 +596,20 @@ class AdminController extends Controller
   }
 
   public function emailReport(Request $request, StoreOrder $order){
-    //$results_attachment = $order->getDetailJsonValue('results_attachment');
+    $results_attachment = $order->getDetailJsonValue('results_attachment');
 
     $emailParams = [
         'toEmail' => $order->user->getEmail(),
         'toName' => $order->user->displayName(),
         'subject' => 'Your Test Results Are Ready',
-        'message' => $request->get('message')
-        //'attachmentPath' => $results_attachment['path']
+        'message' => $request->get('message'),
+        'attachmentPath' => $results_attachment['path']
     ];
     if(!$emailParams['message']){
         $emailParams['message'] = '<p>Your test results are now available in your secure account.</p><p>To view your results, please click the button below to log in:</p>';
     }
 
-    //$response = $this->emailService->sendEmailWithAttachment($emailParams);
+    $response = $this->emailService->sendEmailWithAttachment($emailParams);
     return $this->pass();
 
   }

+ 28 - 3
app/Http/Services/EmailService.php

@@ -242,7 +242,7 @@ class EmailService
         $html = (string) view('emails.templates.attachment', compact('params', 'appUrl', 'emailFromName', 'appInternalName', 'stringMappingConfig'));
         $plainText = (string) '';
 
-       // $attachment = $this->getAttachmentFromStoragePath($params['attachmentPath'], 'attachment1');
+       $attachment = $this->getAttachmentFromStoragePath($params['attachmentPath'], 'attachment1');
 
 
         $emailParams = [
@@ -253,8 +253,8 @@ class EmailService
             'contentHtml' => $html,
             'contentText' => $plainText,
             'entityType' => null,
-            'entityUid' => null
-           // 'attachment1' => $attachment
+            'entityUid' => null,
+           'attachment1' => $attachment
         ];
 
         $response = $this->callJava('/api/email/send', $emailParams, null);
@@ -272,4 +272,29 @@ class EmailService
 
         return null;
     }
+
+    public function emailOrderReportReadyAlert(StoreOrder $storeOrder)
+    {
+        $user = $storeOrder->user;
+        if (!$user->getEmail()) return;
+        $appInternalName = $this->appInternalName;
+        $stringMappingConfig = $this->stringMappingConfig;
+        $appUrl = $this->appUrl;
+        $emailFromName = $this->emailFromName;
+        $html = (string) view('emails.templates.email-order-report-ready-alert', compact('storeOrder', 'user', 'appUrl', 'emailFromName', 'appInternalName', 'stringMappingConfig'));
+        $plainText = (string) '';
+
+        $params = [
+            'fromEmailAddress' => $this->fromEmailAddress,
+            'fromName' => $this->emailFromName,
+            'toEmailAddress' => $user->getEmail(),
+            'subject' => 'Lab Results Report Ready',
+            'contentHtml' => $html,
+            'contentText' => $plainText,
+            'entityType' => 'USER',
+            'entityUid' => $user->uid,
+        ];
+
+        $response = $this->callJava('/api/email/send', $params, null);
+    }
 }

+ 9 - 0
resources/views/emails/templates/email-order-report-ready-alert.blade.php

@@ -0,0 +1,9 @@
+@extends('emails.layout')
+@section('salutation')
+    Hello {{$user->displayName()}},
+@endsection
+
+@section('content')
+<p class="f-fallback" style="color: #000; font-size: 15px; padding: 0 15px; line-height: 24px; margin: .4em 0 1.1875em;">Your lab results report is ready for download. Please click the link below to access lab report results.</p>
+ @include('emails.call-to-action-button', ['link'=>$stringMappingConfig['productUrl'].'/my-account/orders/' . $storeOrder->uid, 'label' => 'View Order Lab Results'])
+@endsection