API
2 years ago
BlockTemplates
2 years ago
Composer
2 years ago
DateTimeProvider
4 years ago
Features
2 years ago
Marketing
2 years ago
Notes
2 years ago
Overrides
3 years ago
PluginsInstallLoggers
2 years ago
PluginsProvider
4 years ago
RemoteInboxNotifications
2 years ago
Schedulers
4 years ago
DataSourcePoller.php
3 years ago
DeprecatedClassFacade.php
2 years ago
FeaturePlugin.php
4 years ago
Loader.php
4 years ago
PageController.php
2 years ago
PluginsHelper.php
2 years ago
PluginsInstaller.php
4 years ago
ReportCSVEmail.php
2 years ago
ReportCSVExporter.php
3 years ago
ReportExporter.php
3 years ago
ReportsSync.php
3 years ago
WCAdminHelper.php
4 years ago
ReportCSVEmail.php
175 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 | /** |
| 25 | * Report labels. |
| 26 | * |
| 27 | * @var array |
| 28 | */ |
| 29 | protected $report_labels; |
| 30 | |
| 31 | /** |
| 32 | * Report type (e.g. 'customers'). |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | protected $report_type; |
| 37 | |
| 38 | /** |
| 39 | * Download URL. |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | protected $download_url; |
| 44 | |
| 45 | /** |
| 46 | * Constructor. |
| 47 | */ |
| 48 | public function __construct() { |
| 49 | $this->id = 'admin_report_export_download'; |
| 50 | $this->template_base = WC()->plugin_path() . '/includes/react-admin/emails/'; |
| 51 | $this->template_html = 'html-admin-report-export-download.php'; |
| 52 | $this->template_plain = 'plain-admin-report-export-download.php'; |
| 53 | $this->report_labels = array( |
| 54 | 'categories' => __( 'Categories', 'woocommerce' ), |
| 55 | 'coupons' => __( 'Coupons', 'woocommerce' ), |
| 56 | 'customers' => __( 'Customers', 'woocommerce' ), |
| 57 | 'downloads' => __( 'Downloads', 'woocommerce' ), |
| 58 | 'orders' => __( 'Orders', 'woocommerce' ), |
| 59 | 'products' => __( 'Products', 'woocommerce' ), |
| 60 | 'revenue' => __( 'Revenue', 'woocommerce' ), |
| 61 | 'stock' => __( 'Stock', 'woocommerce' ), |
| 62 | 'taxes' => __( 'Taxes', 'woocommerce' ), |
| 63 | 'variations' => __( 'Variations', 'woocommerce' ), |
| 64 | ); |
| 65 | |
| 66 | // Call parent constructor. |
| 67 | parent::__construct(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * This email has no user-facing settings. |
| 72 | */ |
| 73 | public function init_form_fields() {} |
| 74 | |
| 75 | /** |
| 76 | * This email has no user-facing settings. |
| 77 | */ |
| 78 | public function init_settings() {} |
| 79 | |
| 80 | /** |
| 81 | * Return email type. |
| 82 | * |
| 83 | * @return string |
| 84 | */ |
| 85 | public function get_email_type() { |
| 86 | return class_exists( 'DOMDocument' ) ? 'html' : 'plain'; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Get email heading. |
| 91 | * |
| 92 | * @return string |
| 93 | */ |
| 94 | public function get_default_heading() { |
| 95 | return __( 'Your Report Download', 'woocommerce' ); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Get email subject. |
| 100 | * |
| 101 | * @return string |
| 102 | */ |
| 103 | public function get_default_subject() { |
| 104 | return __( '[{site_title}]: Your {report_name} Report download is ready', 'woocommerce' ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Get content html. |
| 109 | * |
| 110 | * @return string |
| 111 | */ |
| 112 | public function get_content_html() { |
| 113 | return wc_get_template_html( |
| 114 | $this->template_html, |
| 115 | array( |
| 116 | 'report_name' => $this->report_type, |
| 117 | 'download_url' => $this->download_url, |
| 118 | 'email_heading' => $this->get_heading(), |
| 119 | 'sent_to_admin' => true, |
| 120 | 'plain_text' => false, |
| 121 | 'email' => $this, |
| 122 | ), |
| 123 | '', |
| 124 | $this->template_base |
| 125 | ); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Get content plain. |
| 130 | * |
| 131 | * @return string |
| 132 | */ |
| 133 | public function get_content_plain() { |
| 134 | return wc_get_template_html( |
| 135 | $this->template_plain, |
| 136 | array( |
| 137 | 'report_name' => $this->report_type, |
| 138 | 'download_url' => $this->download_url, |
| 139 | 'email_heading' => $this->get_heading(), |
| 140 | 'sent_to_admin' => true, |
| 141 | 'plain_text' => true, |
| 142 | 'email' => $this, |
| 143 | ), |
| 144 | '', |
| 145 | $this->template_base |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Trigger the sending of this email. |
| 151 | * |
| 152 | * @param int $user_id User ID to email. |
| 153 | * @param string $report_type The type of report export being emailed. |
| 154 | * @param string $download_url The URL for downloading the report. |
| 155 | */ |
| 156 | public function trigger( $user_id, $report_type, $download_url ) { |
| 157 | $user = new \WP_User( $user_id ); |
| 158 | $this->recipient = $user->user_email; |
| 159 | $this->download_url = $download_url; |
| 160 | |
| 161 | if ( isset( $this->report_labels[ $report_type ] ) ) { |
| 162 | $this->report_type = $this->report_labels[ $report_type ]; |
| 163 | $this->placeholders['{report_name}'] = $this->report_type; |
| 164 | } |
| 165 | |
| 166 | $this->send( |
| 167 | $this->get_recipient(), |
| 168 | $this->get_subject(), |
| 169 | $this->get_content(), |
| 170 | $this->get_headers(), |
| 171 | $this->get_attachments() |
| 172 | ); |
| 173 | } |
| 174 | } |
| 175 |