Use the rendered subject in stats email

This commit is contained in:
Amine Ben hammou
2019-08-07 13:54:32 +01:00
committed by Jack Kitterhing
parent 486ef4fe67
commit 83d9c85737
2 changed files with 10 additions and 8 deletions

View File

@ -82,8 +82,9 @@ class Worker {
$newsletter = $this->getNewsletter($task);
$link = NewsletterLink::findTopLinkForNewsletter($newsletter);
$context = $this->prepareContext($newsletter, $link);
$subject = $newsletter->queue['newsletter_rendered_subject'];
return [
'subject' => sprintf(_x('Stats for email %s', 'title of an automatic email containing statistics (newsletter open rate, click rate, etc)', 'mailpoet'), $newsletter->subject),
'subject' => sprintf(_x('Stats for email %s', 'title of an automatic email containing statistics (newsletter open rate, click rate, etc)', 'mailpoet'), $subject),
'body' => [
'html' => $this->renderer->render('emails/statsNotification.html', $context),
'text' => $this->renderer->render('emails/statsNotification.txt', $context),
@ -101,9 +102,9 @@ class Worker {
throw new \Exception('Newsletter not found');
}
return $newsletter
->withSendingQueue()
->withTotalSent()
->withStatistics($this->woocommerce_helper);
->withSendingQueue()
->withTotalSent()
->withStatistics($this->woocommerce_helper);
}
/**
@ -115,8 +116,9 @@ class Worker {
$clicked = ($newsletter->statistics['clicked'] * 100) / $newsletter->total_sent;
$opened = ($newsletter->statistics['opened'] * 100) / $newsletter->total_sent;
$unsubscribed = ($newsletter->statistics['unsubscribed'] * 100) / $newsletter->total_sent;
$subject = $newsletter->queue['newsletter_rendered_subject'];
$context = [
'subject' => $newsletter->subject,
'subject' => $subject,
'preheader' => sprintf(_x(
'%1$s%% opens, %2$s%% clicks, %3$s%% unsubscribes in a nutshell.', 'newsletter open rate, click rate and unsubscribe rate', 'mailpoet'),
number_format($opened, 2),

View File

@ -69,7 +69,7 @@ class WorkerTest extends \MailPoetTest {
'task_id' => $stats_notifications_task->id(),
]);
$this->queue = SendingQueue::createOrUpdate([
'newsletter_rendered_subject' => 'Email Subject',
'newsletter_rendered_subject' => 'Rendered Email Subject',
'task_id' => $sending_task->id(),
'newsletter_id' => $this->newsletter->id(),
'count_processed' => 5,
@ -150,7 +150,7 @@ class WorkerTest extends \MailPoetTest {
->with(
$this->anything(),
$this->callback(function($context){
return $context['subject'] === 'Email Subject1';
return $context['subject'] === 'Rendered Email Subject';
}));
$this->stats_notifications->process();
@ -263,7 +263,7 @@ class WorkerTest extends \MailPoetTest {
'task_id' => $stats_notifications_task->id(),
]);
SendingQueue::createOrUpdate([
'newsletter_rendered_subject' => 'Email Subject2',
'newsletter_rendered_subject' => 'Rendered Email Subject2',
'task_id' => $sending_task->id(),
'newsletter_id' => $newsletter->id(),
'count_processed' => 15,