Merge WC email initialization into newsletters listing page [MAILPOET-2433]

This commit is contained in:
wxa
2020-11-04 13:59:02 +03:00
committed by Veljko V
parent 56868ce0db
commit 4661eab49e
5 changed files with 25 additions and 77 deletions

View File

@ -3,6 +3,7 @@
namespace MailPoet\AdminPages\Pages;
use MailPoet\AdminPages\PageRenderer;
use MailPoet\AutomaticEmails\AutomaticEmails;
use MailPoet\Config\Env;
use MailPoet\Config\Installer;
use MailPoet\Config\Menu;
@ -62,6 +63,9 @@ class Newsletters {
/** @var AddToNewslettersSegments */
private $addToNewslettersSegments;
/** @var AutomaticEmails */
private $automaticEmails;
public function __construct(
PageRenderer $pageRenderer,
PageLimit $listingPageLimit,
@ -74,7 +78,8 @@ class Newsletters {
SubscribersFeature $subscribersFeature,
ServicesChecker $servicesChecker,
NewsletterTemplatesRepository $newsletterTemplatesRepository,
AddToNewslettersSegments $addToNewslettersSegments
AddToNewslettersSegments $addToNewslettersSegments,
AutomaticEmails $automaticEmails
) {
$this->pageRenderer = $pageRenderer;
$this->listingPageLimit = $listingPageLimit;
@ -88,6 +93,7 @@ class Newsletters {
$this->servicesChecker = $servicesChecker;
$this->newsletterTemplatesRepository = $newsletterTemplatesRepository;
$this->addToNewslettersSegments = $addToNewslettersSegments;
$this->automaticEmails = $automaticEmails;
}
public function render() {
@ -153,46 +159,8 @@ class Newsletters {
$data['mss_key_invalid'] = ($this->servicesChecker->isMailPoetAPIKeyValid() === false);
$data['automatic_emails'] = [
[
'slug' => 'woocommerce',
'premium' => true,
'title' => $this->wp->__('WooCommerce', 'mailpoet'),
'description' => $this->wp->__('Automatically send an email based on your customers purchase behavior. Enhance your customer service and start increasing sales with WooCommerce follow up emails.', 'mailpoet'),
'events' => [
[
'slug' => 'woocommerce_abandoned_shopping_cart',
'title' => $this->wp->__('Abandoned Shopping Cart', 'mailpoet'),
'description' => $this->wp->__('Send an email to identified visitors who have items in their shopping carts but left your website without checking out. Can convert up to 20% of abandoned carts.', 'mailpoet'),
'soon' => true,
'badge' => [
'text' => $this->wp->__('Must-have', 'mailpoet'),
'style' => 'red',
],
],
[
'slug' => 'woocommerce_first_purchase',
'title' => $this->wp->__('First Purchase', 'mailpoet'),
'description' => $this->wp->__('Let MailPoet send an email to customers who make their first purchase.', 'mailpoet'),
'badge' => [
'text' => $this->wp->__('Must-have', 'mailpoet'),
'style' => 'red',
],
],
[
'slug' => 'woocommerce_product_purchased_in_category',
'title' => $this->wp->__('Purchased In This Category', 'mailpoet'),
'description' => $this->wp->__('Let MailPoet send an email to customers who purchase a product for the first time in a specific category.', 'mailpoet'),
'soon' => true,
],
[
'slug' => 'woocommerce_product_purchased',
'title' => $this->wp->__('Purchased This Product', 'mailpoet'),
'description' => $this->wp->__('Let MailPoet send an email to customers who purchase a specific product for the first time.', 'mailpoet'),
],
],
],
];
$data['automatic_emails'] = $this->automaticEmails->getAutomaticEmails();
$data['woocommerce_optin_on_checkout'] = $this->settings->get('woocommerce.optin_on_checkout.enabled', false);
$data['is_new_user'] = $this->installation->isNewInstallation();
$data['sent_newsletters_count'] = (int)Newsletter::where('status', Newsletter::STATUS_SENT)->count();

View File

@ -344,12 +344,6 @@ class Initializer {
public function setupAutomaticEmails() {
$automaticEmails = new AutomaticEmails();
$automaticEmails->init();
$this->automaticEmails = $automaticEmails->getAutomaticEmails();
WPFunctions::get()->addAction(
'mailpoet_newsletters_translations_after',
[$this, 'includeAutomaticEmailsData']
);
}
private function setupWoocommerceTransactionalEmails() {
@ -362,13 +356,4 @@ class Initializer {
}
}
}
public function includeAutomaticEmailsData() {
$data = [
'automatic_emails' => $this->automaticEmails,
'woocommerce_optin_on_checkout' => $this->settings->get('woocommerce.optin_on_checkout.enabled', false),
];
echo $this->renderer->render('automatic_emails.html', $data);
}
}

View File

@ -87,6 +87,8 @@ class ContainerConfigurator implements IContainerConfigurator {
$container->autowire(\MailPoet\API\JSON\ResponseBuilders\SubscribersResponseBuilder::class)->setPublic(true);
$container->autowire(\MailPoet\API\JSON\ResponseBuilders\FormsResponseBuilder::class);
$container->autowire(\MailPoet\API\JSON\ResponseBuilders\SegmentsResponseBuilder::class);
// Automatic emails
$container->autowire(\MailPoet\AutomaticEmails\AutomaticEmails::class);
// Config
$container->autowire(\MailPoet\Config\AccessControl::class)->setPublic(true);
$container->autowire(\MailPoet\Config\Activator::class)->setPublic(true);

View File

@ -1,19 +0,0 @@
<script type="text/javascript">
var mailpoet_woocommerce_automatic_emails = <%= json_encode(automatic_emails) %>;
var mailpoet_woocommerce_optin_on_checkout = "<%= woocommerce_optin_on_checkout %>";
</script>
<% block translations %>
<%= localize({
'automaticEmail': __('Automatic Email'),
'tip': __('Tip:'),
'selectAutomaticEmailsEventsConditionsHeading': __("Select %1s events conditions"),
'sendAutomaticEmailWhenHeading': __('Send this %1s Automatic Email when...'),
'automaticEmailActivated': __('Your %1s Automatic Email is now activated!'),
'automaticEmailActivationFailed': __('Your %1s Automatic Email could not be activated, please check the settings.'),
'automaticEmailEventOptionsNotConfigured': __('You need to configure email options before this email can be sent.'),
'sentToXCustomers': __('Sent to %$1d customers'),
'wooCommerceEmailsWarning': __('WooCommerce emails wont be sent to new customers because the opt-in on checkout is disabled. Enable it so they can immediately get your emails after their first purchase.'),
'wooCommerceEmailsWarningLink': __('Edit WooCommerce settings'),
}) %>
<% endblock %>

View File

@ -34,10 +34,12 @@
var mailpoet_account_url = '<%= add_referral_id("https://account.mailpoet.com/?s=" ~ subscriber_count ~ "&email=" ~ current_wp_user.user_email) | escape('js') %>';
var mailpoet_feature_flags = <%= json_encode(mailpoet_feature_flags) %>;
var mailpoet_woocommerce_automatic_emails = <%= json_encode(automatic_emails) %>;
var mailpoet_woocommerce_optin_on_checkout = "<%= woocommerce_optin_on_checkout %>";
var mailpoet_woocommerce_active = <%= json_encode(is_woocommerce_active) %>;
var mailpoet_woocommerce_transactional_email_id = <%= json_encode(woocommerce_transactional_email_id) %>;
var mailpoet_display_detailed_stats = <%= json_encode(display_detailed_stats) %>;
var mailpoet_automatic_emails = <%= json_encode(automatic_emails) %>;
var mailpoet_last_announcement_seen = <%= json_encode(last_announcement_seen) %>;
var mailpoet_user_locale = '<%= get_locale() %>';
var mailpoet_congratulations_success_images = [
@ -383,7 +385,6 @@
'soon': __('Soon'),
'beta': __('Beta'),
'errorWhileTakingScreenshot': __('An error occurred while saving the template in "Recently sent"'),
'selectAutomaticEmailsEventsHeading': __('Select %$1s events'),
'cronNotAccessibleNotice': __('Oops! There seems to be an issue with the sending on your website. [link]See our guide[/link] to solve this yourself.'),
'whatsNew': __("Whats new"),
@ -435,6 +436,17 @@
'gaCampaignLine': __('Google Analytics Campaign'),
'gaCampaignTip': __('For example, “Spring email”. [link]Read the guide.[/link]'),
'automaticEmail': __('Automatic Email'),
'tip': __('Tip:'),
'selectAutomaticEmailsEventsConditionsHeading': __("Select %1s events conditions"),
'sendAutomaticEmailWhenHeading': __('Send this %1s Automatic Email when...'),
'automaticEmailActivated': __('Your %1s Automatic Email is now activated!'),
'automaticEmailActivationFailed': __('Your %1s Automatic Email could not be activated, please check the settings.'),
'automaticEmailEventOptionsNotConfigured': __('You need to configure email options before this email can be sent.'),
'sentToXCustomers': __('Sent to %$1d customers'),
'wooCommerceEmailsWarning': __('WooCommerce emails wont be sent to new customers because the opt-in on checkout is disabled. Enable it so they can immediately get your emails after their first purchase.'),
'wooCommerceEmailsWarningLink': __('Edit WooCommerce settings'),
}) %>
<% include('mss_pitch_translations.html') %>
<% endblock %>