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:
@@ -70,6 +70,12 @@ class NotificationManager {
|
||||
* @return bool
|
||||
*/
|
||||
public static function should_send_notification($event_id, $channel_id) {
|
||||
// Check if WooNooW notification system is enabled
|
||||
$system_mode = get_option('woonoow_notification_system_mode', 'woonoow');
|
||||
if ($system_mode !== 'woonoow') {
|
||||
return false; // Use WooCommerce default emails instead
|
||||
}
|
||||
|
||||
// Check if channel is globally enabled
|
||||
if (!self::is_channel_enabled($channel_id)) {
|
||||
return false;
|
||||
@@ -151,10 +157,22 @@ class NotificationManager {
|
||||
* @return bool
|
||||
*/
|
||||
private static function send_email($event_id, $recipient, $data) {
|
||||
// Email sending will be handled by WooCommerce email system
|
||||
// This is a placeholder for future implementation
|
||||
do_action('woonoow_send_email_notification', $event_id, $recipient, $data);
|
||||
return true;
|
||||
// Use EmailRenderer to render the email
|
||||
$renderer = EmailRenderer::instance();
|
||||
$email_data = $renderer->render($event_id, $recipient, $data['order'] ?? $data['product'] ?? $data['customer'] ?? null, $data);
|
||||
|
||||
if (!$email_data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send email using wp_mail
|
||||
$headers = ['Content-Type: text/html; charset=UTF-8'];
|
||||
$sent = wp_mail($email_data['to'], $email_data['subject'], $email_data['body'], $headers);
|
||||
|
||||
// Trigger action for logging/tracking
|
||||
do_action('woonoow_email_sent', $event_id, $recipient, $email_data, $sent);
|
||||
|
||||
return $sent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user