API
4 years ago
Composer
4 years ago
DateTimeProvider
4 years ago
Features
4 years ago
Marketing
4 years ago
Notes
4 years ago
Overrides
4 years ago
PluginsProvider
4 years ago
RemoteInboxNotifications
4 years ago
Schedulers
4 years ago
DataSourcePoller.php
4 years ago
DeprecatedClassFacade.php
4 years ago
Loader.php
4 years ago
PageController.php
4 years ago
PluginsHelper.php
4 years ago
PluginsInstaller.php
4 years ago
ReportCSVEmail.php
4 years ago
ReportCSVExporter.php
4 years ago
ReportExporter.php
4 years ago
ReportsSync.php
4 years ago
WCAdminHelper.php
4 years ago
ReportCSVEmail.php
153 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles emailing users CSV Export download links. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin; |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Include dependencies. |
| 14 | */ |
| 15 | if ( ! class_exists( 'WC_Email', false ) ) { |
| 16 | include_once WC_ABSPATH . 'includes/emails/class-wc-email.php'; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * ReportCSVEmail Class. |
| 21 | */ |
| 22 | class ReportCSVEmail extends \WC_Email { |
| 23 | /** |
| 24 | * Constructor. |
| 25 | */ |
| 26 | public function __construct() { |
| 27 | $this->id = 'admin_report_export_download'; |
| 28 | $this->template_base = WC()->plugin_path() . '/includes/react-admin/emails/'; |
| 29 | $this->template_html = 'html-admin-report-export-download.php'; |
| 30 | $this->template_plain = 'plain-admin-report-export-download.php'; |
| 31 | $this->report_labels = array( |
| 32 | 'categories' => __( 'Categories', 'woocommerce' ), |
| 33 | 'coupons' => __( 'Coupons', 'woocommerce' ), |
| 34 | 'customers' => __( 'Customers', 'woocommerce' ), |
| 35 | 'downloads' => __( 'Downloads', 'woocommerce' ), |
| 36 | 'orders' => __( 'Orders', 'woocommerce' ), |
| 37 | 'products' => __( 'Products', 'woocommerce' ), |
| 38 | 'revenue' => __( 'Revenue', 'woocommerce' ), |
| 39 | 'stock' => __( 'Stock', 'woocommerce' ), |
| 40 | 'taxes' => __( 'Taxes', 'woocommerce' ), |
| 41 | 'variations' => __( 'Variations', 'woocommerce' ), |
| 42 | ); |
| 43 | |
| 44 | // Call parent constructor. |
| 45 | parent::__construct(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * This email has no user-facing settings. |
| 50 | */ |
| 51 | public function init_form_fields() {} |
| 52 | |
| 53 | /** |
| 54 | * This email has no user-facing settings. |
| 55 | */ |
| 56 | public function init_settings() {} |
| 57 | |
| 58 | /** |
| 59 | * Return email type. |
| 60 | * |
| 61 | * @return string |
| 62 | */ |
| 63 | public function get_email_type() { |
| 64 | return class_exists( 'DOMDocument' ) ? 'html' : 'plain'; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Get email heading. |
| 69 | * |
| 70 | * @return string |
| 71 | */ |
| 72 | public function get_default_heading() { |
| 73 | return __( 'Your Report Download', 'woocommerce' ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get email subject. |
| 78 | * |
| 79 | * @return string |
| 80 | */ |
| 81 | public function get_default_subject() { |
| 82 | return __( '[{site_title}]: Your {report_name} Report download is ready', 'woocommerce' ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Get content html. |
| 87 | * |
| 88 | * @return string |
| 89 | */ |
| 90 | public function get_content_html() { |
| 91 | return wc_get_template_html( |
| 92 | $this->template_html, |
| 93 | array( |
| 94 | 'report_name' => $this->report_type, |
| 95 | 'download_url' => $this->download_url, |
| 96 | 'email_heading' => $this->get_heading(), |
| 97 | 'sent_to_admin' => true, |
| 98 | 'plain_text' => false, |
| 99 | 'email' => $this, |
| 100 | ), |
| 101 | '', |
| 102 | $this->template_base |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Get content plain. |
| 108 | * |
| 109 | * @return string |
| 110 | */ |
| 111 | public function get_content_plain() { |
| 112 | return wc_get_template_html( |
| 113 | $this->template_plain, |
| 114 | array( |
| 115 | 'report_name' => $this->report_type, |
| 116 | 'download_url' => $this->download_url, |
| 117 | 'email_heading' => $this->get_heading(), |
| 118 | 'sent_to_admin' => true, |
| 119 | 'plain_text' => true, |
| 120 | 'email' => $this, |
| 121 | ), |
| 122 | '', |
| 123 | $this->template_base |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Trigger the sending of this email. |
| 129 | * |
| 130 | * @param int $user_id User ID to email. |
| 131 | * @param string $report_type The type of report export being emailed. |
| 132 | * @param string $download_url The URL for downloading the report. |
| 133 | */ |
| 134 | public function trigger( $user_id, $report_type, $download_url ) { |
| 135 | $user = new \WP_User( $user_id ); |
| 136 | $this->recipient = $user->user_email; |
| 137 | $this->download_url = $download_url; |
| 138 | |
| 139 | if ( isset( $this->report_labels[ $report_type ] ) ) { |
| 140 | $this->report_type = $this->report_labels[ $report_type ]; |
| 141 | $this->placeholders['{report_name}'] = $this->report_type; |
| 142 | } |
| 143 | |
| 144 | $this->send( |
| 145 | $this->get_recipient(), |
| 146 | $this->get_subject(), |
| 147 | $this->get_content(), |
| 148 | $this->get_headers(), |
| 149 | $this->get_attachments() |
| 150 | ); |
| 151 | } |
| 152 | } |
| 153 |