Files
WooNooW/includes/Api/Routes.php
dwindown 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
2025-11-11 12:11:08 +07:00

90 lines
3.3 KiB
PHP

<?php
namespace WooNooW\Api;
use WP_REST_Request;
use WP_REST_Response;
use WooNooW\Api\CheckoutController;
use WooNooW\Api\OrdersController;
use WooNooW\Api\AnalyticsController;
use WooNooW\Api\AuthController;
use WooNooW\API\PaymentsController;
use WooNooW\API\StoreController;
use WooNooW\Api\ShippingController;
use WooNooW\Api\TaxController;
use WooNooW\Api\PickupLocationsController;
use WooNooW\Api\EmailController;
use WooNooW\API\DeveloperController;
use WooNooW\API\SystemController;
use WooNooW\Api\NotificationsController;
class Routes {
public static function init() {
// Initialize controllers (register action hooks)
OrdersController::init();
add_action('rest_api_init', function () {
$namespace = 'woonoow/v1';
// Auth endpoints (public - no permission check)
register_rest_route( $namespace, '/auth/login', [
'methods' => 'POST',
'callback' => [ AuthController::class, 'login' ],
'permission_callback' => '__return_true',
] );
register_rest_route( $namespace, '/auth/logout', [
'methods' => 'POST',
'callback' => [ AuthController::class, 'logout' ],
'permission_callback' => '__return_true',
] );
register_rest_route( $namespace, '/auth/check', [
'methods' => 'GET',
'callback' => [ AuthController::class, 'check' ],
'permission_callback' => '__return_true',
] );
// Defer to controllers to register their endpoints
CheckoutController::register();
OrdersController::register();
AnalyticsController::register_routes();
// Payments controller
$payments_controller = new PaymentsController();
$payments_controller->register_routes();
// Store controller
$store_controller = new StoreController();
$store_controller->register_routes();
// Shipping controller
$shipping_controller = new ShippingController();
$shipping_controller->register_routes();
// Tax controller
$tax_controller = new TaxController();
$tax_controller->register_routes();
// Pickup locations controller
$pickup_controller = new PickupLocationsController();
$pickup_controller->register_routes();
// Email controller
$email_controller = new EmailController();
$email_controller->register_routes();
// Developer controller
$developer_controller = new DeveloperController();
$developer_controller->register_routes();
// System controller
$system_controller = new SystemController();
$system_controller->register_routes();
// Notifications controller
$notifications_controller = new NotificationsController();
$notifications_controller->register_routes();
});
}
}