diff --git a/lib/Cron/Workers/StatsNotifications/Worker.php b/lib/Cron/Workers/StatsNotifications/Worker.php index 493857e4e0..540a34a330 100644 --- a/lib/Cron/Workers/StatsNotifications/Worker.php +++ b/lib/Cron/Workers/StatsNotifications/Worker.php @@ -13,9 +13,11 @@ use MailPoet\Mailer\Mailer; use MailPoet\Mailer\MetaInfo; use MailPoet\Models\NewsletterLink; use MailPoet\Models\ScheduledTask; +use MailPoet\Models\Subscriber; use MailPoet\Newsletter\Statistics\NewsletterStatisticsRepository; use MailPoet\Settings\SettingsController; use MailPoet\Tasks\Sending; +use MailPoet\Util\License\Features\Subscribers as SubscribersFeature; use MailPoet\WP\Functions as WPFunctions; use MailPoetVendor\Doctrine\ORM\EntityManager; @@ -51,6 +53,9 @@ class Worker { /** @var NewsletterStatisticsRepository */ private $newsletter_statistics_repository; + /** @var SubscribersFeature */ + private $subscribers_feature; + function __construct( Mailer $mailer, Renderer $renderer, @@ -60,7 +65,8 @@ class Worker { StatsNotificationsRepository $repository, NewsletterLinkRepository $newsletter_link_repository, NewsletterStatisticsRepository $newsletter_statistics_repository, - EntityManager $entity_manager + EntityManager $entity_manager, + SubscribersFeature $subscribers_feature ) { $this->renderer = $renderer; $this->mailer = $mailer; @@ -71,6 +77,7 @@ class Worker { $this->entity_manager = $entity_manager; $this->newsletter_link_repository = $newsletter_link_repository; $this->newsletter_statistics_repository = $newsletter_statistics_repository; + $this->subscribers_feature = $subscribers_feature; } /** @throws \Exception */ @@ -114,6 +121,7 @@ class Worker { $opened = ($statistics->getOpenCount() * 100) / $statistics->getTotalSentCount(); $unsubscribed = ($statistics->getUnsubscribeCount() * 100) / $statistics->getTotalSentCount(); $subject = $newsletter->getLatestQueue()->getNewsletterRenderedSubject(); + $subscribers_count = Subscriber::getTotalSubscribers(); $context = [ 'subject' => $subject, 'preheader' => sprintf(_x( @@ -127,6 +135,9 @@ class Worker { 'linkStats' => WPFunctions::get()->getSiteUrl(null, '/wp-admin/admin.php?page=mailpoet-newsletters#/stats/' . $newsletter->getId()), 'clicked' => $clicked, 'opened' => $opened, + 'subscribersLimitReached' => $this->subscribers_feature->check(), + 'subscribersLimit' => $this->subscribers_feature->getSubscribersLimit(), + 'upgradeNowLink' => 'https://account.mailpoet.com/?s=' . ($subscribers_count + 1), ]; if ($link) { $context['topLinkClicks'] = $link->getTotalClicksCount(); diff --git a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php index c657a58bdd..c62f0c3b19 100644 --- a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php +++ b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php @@ -17,6 +17,7 @@ use MailPoet\Models\StatisticsOpens; use MailPoet\Models\StatisticsUnsubscribes; use MailPoet\Newsletter\Statistics\NewsletterStatisticsRepository; use MailPoet\Settings\SettingsController; +use MailPoet\Util\License\Features\Subscribers as SubscribersFeature; use MailPoetVendor\Idiorm\ORM; use PHPUnit\Framework\MockObject\MockObject; @@ -71,7 +72,8 @@ class WorkerTest extends \MailPoetTest { $this->repository, $this->newsletter_link_repository, ContainerWrapper::getInstance()->get(NewsletterStatisticsRepository::class), - $this->entity_manager + $this->entity_manager, + ContainerWrapper::getInstance()->get(SubscribersFeature::class) ); $this->settings->set(Worker::SETTINGS_KEY, [ 'enabled' => true, diff --git a/views/emails/statsNotification.html b/views/emails/statsNotification.html index 072cb5ceb4..1c212af261 100644 --- a/views/emails/statsNotification.html +++ b/views/emails/statsNotification.html @@ -45,6 +45,84 @@ + <% if subscribersLimitReached %> + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + +
+ <%= __('Congratulations, you now have more than [subscribersLimit] subscribers!')|replace({'[subscribersLimit]': subscribersLimit}) %>

+
+ + + +
+ +
+ + + +
+ <%= __('Our free version is limited to [subscribersLimit] subscribers. You need to upgrade now to be able to continue using MailPoet.')|replace({'[subscribersLimit]': subscribersLimit}) %> +
+
+
+ + + + +
Upgrade Now +
+
+
+
+ + + <% endif %> diff --git a/views/emails/statsNotification.txt b/views/emails/statsNotification.txt index 3809f80e6c..82a48fa833 100644 --- a/views/emails/statsNotification.txt +++ b/views/emails/statsNotification.txt @@ -5,6 +5,15 @@ <%= subject %> +<% if subscribersLimitReached %> +<%= __('Congratulations, you now have more than [subscribersLimit] subscribers!')|replace({'[subscribersLimit]': subscribersLimit}) %> + +<%= __('Our free version is limited to [subscribersLimit] subscribers. You need to upgrade now to be able to continue using MailPoet.')|replace({'[subscribersLimit]': subscribersLimit}) %> + +<%= __('Upgrade Now') %> + <%= upgradeNowLink %> +<% endif %> + <%= __('open rate') %>: <%= number_format_i18n(opened) %>% <%= opened_stats_text(opened) %>