feat: Complete backend wiring for notification system

 Global System Toggle:
- Added GET/POST /notifications/system-mode endpoints
- Switch between WooNooW and WooCommerce notification systems
- Stored in: woonoow_notification_system_mode
- EmailManager::is_enabled() checks system mode
- NotificationManager checks mode before sending

 Template System Wired:
- Templates saved via API are used when sending
- EmailRenderer fetches templates from TemplateProvider
- Variables replaced automatically
- Markdown parsed (cards, buttons, images)
- Email customization applied (colors, logo, branding)

 Channel Toggle Wired:
- Frontend toggles saved to database
- NotificationManager::is_channel_enabled() checks before sending
- Email: woonoow_email_notifications_enabled
- Push: woonoow_push_notifications_enabled

 Event Toggle Wired:
- Per-event channel settings saved
- NotificationManager::is_event_channel_enabled() checks before sending
- Stored in: woonoow_notification_settings

 Email Sending Flow:
Event → EmailManager → Check System Mode → Check Channel Toggle
→ Check Event Toggle → EmailRenderer → Get Template → Replace Variables
→ Parse Markdown → Apply Branding → wp_mail() → Sent

 All Settings Applied:
- Template modifications saved and used
- Channel toggles respected
- Event toggles respected
- Global system mode respected
- Email customization applied
- Push settings applied

📋 Modified Files:
- NotificationsController.php: Added system-mode endpoints
- NotificationManager.php: Added system mode check, wired EmailRenderer
- EmailManager.php: Added is_enabled() check for system mode

🎯 Result: Complete end-to-end notification system fully functional
This commit is contained in:
dwindown
2025-11-15 21:59:46 +07:00
parent a5a2e0b9c0
commit 60658c6786
4 changed files with 161 additions and 12 deletions

View File

@@ -199,6 +199,24 @@ class NotificationsController {
'permission_callback' => [$this, 'check_permission'],
],
]);
// GET /woonoow/v1/notifications/system-mode
register_rest_route($this->namespace, '/' . $this->rest_base . '/system-mode', [
[
'methods' => 'GET',
'callback' => [$this, 'get_system_mode'],
'permission_callback' => [$this, 'check_permission'],
],
]);
// POST /woonoow/v1/notifications/system-mode
register_rest_route($this->namespace, '/' . $this->rest_base . '/system-mode', [
[
'methods' => 'POST',
'callback' => [$this, 'set_system_mode'],
'permission_callback' => [$this, 'check_permission'],
],
]);
}
/**
@@ -799,4 +817,56 @@ class NotificationsController {
return $sanitized;
}
/**
* Get notification system mode
*
* @param WP_REST_Request $request Request object
* @return WP_REST_Response
*/
public function get_system_mode(WP_REST_Request $request) {
$mode = get_option('woonoow_notification_system_mode', 'woonoow');
return new WP_REST_Response([
'mode' => $mode,
'available_modes' => [
'woonoow' => __('WooNooW Notifications', 'woonoow'),
'woocommerce' => __('WooCommerce Default Emails', 'woonoow'),
],
], 200);
}
/**
* Set notification system mode
*
* @param WP_REST_Request $request Request object
* @return WP_REST_Response|WP_Error
*/
public function set_system_mode(WP_REST_Request $request) {
$params = $request->get_json_params();
$mode = isset($params['mode']) ? $params['mode'] : null;
if (!in_array($mode, ['woonoow', 'woocommerce'])) {
return new WP_Error(
'invalid_mode',
__('Invalid notification system mode', 'woonoow'),
['status' => 400]
);
}
// Update the mode
update_option('woonoow_notification_system_mode', $mode);
// Trigger action for other systems to react
do_action('woonoow_notification_system_mode_changed', $mode);
return new WP_REST_Response([
'success' => true,
'mode' => $mode,
'message' => sprintf(
__('Notification system switched to %s', 'woonoow'),
$mode === 'woonoow' ? __('WooNooW', 'woonoow') : __('WooCommerce', 'woonoow')
),
], 200);
}
}