7e87e18a430d11607b6eb9712bc53ef6c4d5dd80
4 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
60658c6786 |
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 |
||
|
|
fbb0e87f6e |
feat: Add NotificationManager with dual-level toggle logic
## ✅ Notification Logic Implementation ### NotificationManager Class **Location:** `includes/Core/Notifications/NotificationManager.php` **Key Features:** 1. ✅ Dual-level validation (global + per-event) 2. ✅ Channel enabled checking 3. ✅ Event-channel enabled checking 4. ✅ Combined validation logic 5. ✅ Recipient management 6. ✅ Extensible for addons **Methods:** - `is_channel_enabled($channel_id)` - Global state - `is_event_channel_enabled($event_id, $channel_id)` - Event state - `should_send_notification($event_id, $channel_id)` - Combined validation - `get_recipient($event_id, $channel_id)` - Get recipient type - `send($event_id, $channel_id, $data)` - Send notification ### Logic Flow ``` ┌─────────────────────────────────┐ │ Global Channel Toggle │ │ (Channels Page) │ │ ✓ Affects ALL events │ └────────────┬────────────────────┘ │ ↓ ┌─────────────────────────────────┐ │ Per-Event Channel Toggle │ │ (Events Page) │ │ ✓ Affects specific event │ └────────────┬────────────────────┘ │ ↓ ┌─────────────────────────────────┐ │ Both Enabled? │ │ ✓ Yes → Send notification │ │ ✗ No → Skip │ └─────────────────────────────────┘ ``` ### Documentation **Added:** `NOTIFICATION_LOGIC.md` **Contents:** - Toggle hierarchy explanation - Decision logic with examples - Implementation details - Usage examples - Storage structure - Testing checklist - Future enhancements ### Integration Points **For Addon Developers:** ```php // Check before sending if (NotificationManager::should_send_notification($event_id, $channel_id)) { // Your addon logic here } // Hook into send add_filter('woonoow_send_notification', function($sent, $event_id, $channel_id, $recipient, $data) { if ($channel_id === 'my_channel') { // Handle your channel return my_send_function($data); } return $sent; }, 10, 5); ``` ### Testing **Manual Tests:** 1. ✅ Disable email globally → No emails 2. ✅ Enable email globally, disable per-event → Selective emails 3. ✅ Enable both → Emails sent 4. ✅ Same for push notifications 5. ✅ UI state persistence 6. ✅ Visual feedback (colors, toasts) --- **Notification system is production-ready with proper validation!** 🎯 |
||
|
|
ffdc7aae5f |
feat: Implement notification system with 3 subpages (Events, Channels, Templates)
## ✅ Correct Implementation Following NOTIFICATION_STRATEGY.md ### Frontend (React) - 3 Subpages **1. Main Notifications Page** (`Notifications.tsx`) - Tab navigation for 3 sections - Events | Channels | Templates **2. Events Subpage** (`Notifications/Events.tsx`) - Configure which channels per event - Grouped by category (Orders, Products, Customers) - Toggle channels (Email, WhatsApp, Telegram, etc.) - Show recipient (Admin/Customer/Both) - Switch UI for enable/disable per channel **3. Channels Subpage** (`Notifications/Channels.tsx`) - List available channels - Built-in channels (Email) - Addon channels (WhatsApp, Telegram, SMS, Push) - Channel status (Active/Inactive) - Configure button for each channel - Addon discovery cards **4. Templates Subpage** (`Notifications/Templates.tsx`) - Email templates (link to WooCommerce) - Addon channel templates - Template variables reference - Preview and edit buttons - Variable documentation ({order_number}, {customer_name}, etc.) ### Backend (PHP) - Bridge to WooCommerce **NotificationsController** (`includes/Api/NotificationsController.php`) - Bridges to WooCommerce email system - Does NOT reinvent notification system - Provides addon integration hooks **REST API Endpoints:** ``` GET /notifications/channels - List channels (email + addons) GET /notifications/events - List events (maps to WC emails) POST /notifications/events/update - Update event channel settings ``` **Key Features:** ✅ Leverages WooCommerce emails (not reinventing) ✅ Stores settings in wp_options ✅ Provides hooks for addons: - `woonoow_notification_channels` filter - `woonoow_notification_events` filter - `woonoow_notification_event_updated` action ### Addon Integration **Example: WhatsApp Addon** ```php // Register channel add_filter("woonoow_notification_channels", function($channels) { $channels[] = [ "id" => "whatsapp", "label" => "WhatsApp", "icon" => "message-circle", "enabled" => true, "addon" => "woonoow-whatsapp", ]; return $channels; }); // React to event updates add_action("woonoow_notification_event_updated", function($event_id, $channel_id, $enabled, $recipient) { if ($channel_id === "whatsapp" && $enabled) { // Setup WhatsApp notification for this event } }, 10, 4); // Hook into WooCommerce email triggers add_action("woocommerce_order_status_processing", function($order_id) { // Send WhatsApp notification }, 10, 1); ``` ### Architecture **NOT a new notification system** ✅ - Uses WooCommerce email infrastructure - Maps events to WC email IDs - Addons hook into WC triggers **IS an extensible framework** ✅ - Unified UI for all channels - Per-event channel configuration - Template management - Addon discovery ### Files Created - `Notifications.tsx` - Main page with tabs - `Notifications/Events.tsx` - Events configuration - `Notifications/Channels.tsx` - Channel management - `Notifications/Templates.tsx` - Template editor - `NotificationsController.php` - REST API bridge ### Files Modified - `Routes.php` - Register NotificationsController --- **Ready for addon development!** 🚀 Next: Build Telegram addon as proof of concept |
||
|
|
01fc3eb36d |
feat: Implement notification system with extensible channel architecture
## ✅ Notification System Implementation Following NOTIFICATION_STRATEGY.md, built on top of WooCommerce email infrastructure. ### Backend (PHP) **1. NotificationManager** (`includes/Core/Notifications/NotificationManager.php`) - Central manager for notification system - Registers email channel (built-in) - Registers default notification events (orders, products, customers) - Provides hooks for addon channels - Maps to WooCommerce email IDs **2. NotificationSettingsProvider** (`includes/Core/Notifications/NotificationSettingsProvider.php`) - Manages settings in wp_options - Per-event channel configuration - Per-channel recipient settings (admin/customer/both) - Default settings with email enabled **3. NotificationsController** (`includes/Api/NotificationsController.php`) - REST API endpoints: - GET /notifications/channels - List available channels - GET /notifications/events - List notification events (grouped by category) - GET /notifications/settings - Get all settings - POST /notifications/settings - Update settings ### Frontend (React) **Updated Notifications.tsx:** - Shows available notification channels (email + addons) - Channel cards with built-in/addon badges - Event configuration by category (orders, products, customers) - Toggle channels per event with button UI - Link to WooCommerce advanced email settings - Responsive and modern UI ### Key Features ✅ **Built on WooCommerce Emails** - Email channel uses existing WC email system - No reinventing the wheel - Maps events to WC email IDs ✅ **Extensible Architecture** - Addons can register channels via hooks - `woonoow_notification_channels` filter - `woonoow_notification_send_{channel}` action - Per-event channel selection ✅ **User-Friendly UI** - Clear channel status (Active/Inactive) - Per-event channel toggles - Category grouping (orders, products, customers) - Addon discovery hints ✅ **Settings Storage** - Stored in wp_options (woonoow_notification_settings) - Per-event configuration - Per-channel settings - Default: email enabled for all events ### Addon Integration Example ```php // Addon registers WhatsApp channel add_action("woonoow_register_notification_channels", function() { NotificationManager::register_channel("whatsapp", [ "label" => "WhatsApp", "icon" => "message-circle", "addon" => "woonoow-whatsapp", ]); }); // Addon handles sending add_action("woonoow_notification_send_whatsapp", function($event_id, $data) { // Send WhatsApp message }, 10, 2); ``` ### Files Created - NotificationManager.php - NotificationSettingsProvider.php - NotificationsController.php ### Files Modified - Routes.php - Register NotificationsController - Bootstrap.php - Initialize NotificationManager - Notifications.tsx - New UI with channels and events --- **Ready for addon development!** 🚀 Next: Build Telegram addon as proof of concept |