PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
← All changes | app/Http/Controllers/EmailNotificationController.php +30 -0 1.4.1 → 1.6.5 View file →
@@ -55,8 +55,12 @@
55 55 }
56 56
57 57 $pdfTemplates = $hasFluentPdf ? (new ReceiptPdfTemplateService())->getTemplateList() : [];
58 58
59 + // Let add-ons inject their custom field data (settings.extra / extra_fields)
60 + // into the editor payload from their own storage.
61 + $notification = apply_filters('fluent_cart/email_notification_data', $notification, $name);
62 +
59 63 return $this->sendSuccess([
60 64 'data' => $notification,
61 65 'shortcodes' => EditorShortCodeHelper::getEmailNotificationShortcodes(),
62 66 'has_fluent_pdf' => $hasFluentPdf,
@@ -85,8 +89,12 @@
85 89 $settings = apply_filters('fluent_cart/prepare_email_template_data', $settingsWithoutTemplate, $settings);
86 90
87 91 $updated = EmailNotifications::updateNotification($notification, $settings);
88 92 if ($updated) {
93 + // Core does not persist custom fields (settings.extra). It fires this after a
94 + // successful update so add-ons can store their own data in their own storage.
95 + do_action('fluent_cart/email_notification_updated', $notification, $settings);
96 +
89 97 return $this->sendSuccess([
90 98 'message' => __('Notification updated successfully', 'fluent-cart')
91 99 ]);
92 100 } else {
@@ -130,10 +138,32 @@
130 138
131 139 public function previewDefaultTemplate(Request $request)
132 140 {
133 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 +
134 156 $previewService = new EmailPreviewService();
135 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]);
136 166
137 167 $body = TemplateService::getTemplateByPathName($template, $data);
138 168
139 169 // Wrap in the same outer email template used by actual emails