← All changes
|
app/Http/Controllers/EmailNotificationController.php
+22
-0
1.5.2
→
1.6.5
View file →
| @@ -138,10 +138,32 @@ | ||
| 138 | 138 | |
| 139 | 139 | public function previewDefaultTemplate(Request $request) |
| 140 | 140 | { |
| 141 | 141 | $template = sanitize_text_field($request->get('template')); |
| 142 | + | |
| 143 | + // Validate the template against the known notification template paths so an | |
| 144 | + // invalid or missing value returns a clean REST error instead of an uncaught | |
| 145 | + // "view not found" fatal from the template renderer. | |
| 146 | + $validTemplates = array_filter(array_column( | |
| 147 | + EmailNotifications::getNotifications(), 'template_path' | |
| 148 | + )); | |
| 149 | + | |
| 150 | + if (!$template || !in_array($template, $validTemplates, true)) { | |
| 151 | + return $this->sendError([ | |
| 152 | + 'message' => __('Invalid or missing "template" parameter.', 'fluent-cart') | |
| 153 | + ], 422); | |
| 154 | + } | |
| 155 | + | |
| 142 | 156 | $previewService = new EmailPreviewService(); |
| 143 | 157 | $data = $previewService->getPreviewData($template); |
| 158 | + | |
| 159 | + // Let add-ons adjust the preview data for their own templates — e.g. unset | |
| 160 | + // `order` so an orderless notification (wishlist, withdrawal, …) previews | |
| 161 | + // without the order header (emails.parts.order_header renders only when | |
| 162 | + // $order is non-empty), or add the sample context their smartcodes need. | |
| 163 | + // Core templates are untouched: no core listener changes $data. The context | |
| 164 | + // is an array so more keys can be added later without changing the signature. | |
| 165 | + $data = apply_filters('fluent_cart/email/preview_data', $data, ['template' => $template]); | |
| 144 | 166 | |
| 145 | 167 | $body = TemplateService::getTemplateByPathName($template, $data); |
| 146 | 168 | |
| 147 | 169 | // Wrap in the same outer email template used by actual emails |