# ⚠️ Backend Integration Required
## Issues Found
### Issue #1: Incorrect Template Count in UI ❌
**Problem:**
The Staff Notifications page shows "9 templates" but there are only **7 staff events**.
**Location:**
`admin-spa/src/routes/Settings/Notifications/Templates.tsx` line 132
**Current Code:**
```tsx
' . __('You have received a new order...', 'woonoow') . '
[/card]' ``` The new `DefaultTemplates.php` uses clean markdown: ```php return '[card type="hero"] New order received! A customer has placed a new order. Please review and process. [/card]' ``` **Root Cause:** The backend API controller is still calling the old `DefaultEmailTemplates` class instead of the new `DefaultTemplates` class. --- ## Required Backend Changes ### 1. Update Default Templates Integration **Option A: Replace Old Class (Recommended)** Replace `includes/Core/Notifications/DefaultEmailTemplates.php` with a wrapper that uses the new class: ```php 'order_placed', 'order_processing' => 'order_confirmed', 'order_completed' => 'order_completed', 'order_cancelled' => 'order_cancelled', 'order_refunded' => 'order_cancelled', // Map to cancelled for now 'low_stock' => 'order_placed', // Placeholder 'out_of_stock' => 'order_placed', // Placeholder 'new_customer' => 'customer_registered', 'customer_note' => 'order_placed', // Placeholder ]; $newEventId = $eventMap[$event_id] ?? $event_id; // Get templates from new class $allTemplates = NewDefaultTemplates::get_all_templates(); $templates = $allTemplates[$recipient_type] ?? []; if (isset($templates[$newEventId])) { return [ 'subject' => NewDefaultTemplates::get_default_subject($recipient_type, $newEventId), 'body' => $templates[$newEventId], ]; } // Fallback return [ 'subject' => __('Notification from {store_name}', 'woonoow'), 'body' => '[card]New notification[/card]', ]; } } ``` **Option B: Update API Controller Directly** Update the API controller to use the new `DefaultTemplates` class: ```php use WooNooW\Email\DefaultTemplates; // In the get_template endpoint: $templates = DefaultTemplates::get_all_templates(); $subject = DefaultTemplates::get_default_subject($recipient_type, $event_id); $body = $templates[$recipient_type][$event_id] ?? ''; ``` --- ### 2. Fix Event Counts in API **Update:** `includes/Api/NotificationsController.php` The `/notifications/events` endpoint should return events with recipient type information: ```php public function get_events($request) { $events = [ 'orders' => [ [ 'id' => 'order_placed', 'label' => __('Order Placed'), 'description' => __('When a new order is placed'), 'recipients' => ['customer', 'staff'], // ← Add this ], [ 'id' => 'order_confirmed', 'label' => __('Order Confirmed'), 'description' => __('When order is confirmed'), 'recipients' => ['customer', 'staff'], // ← Add this ], // ... etc ], 'customers' => [ [ 'id' => 'customer_registered', 'label' => __('Customer Registered'), 'description' => __('When customer creates account'), 'recipients' => ['customer'], // ← Customer only ], [ 'id' => 'customer_vip_upgraded', 'label' => __('VIP Upgraded'), 'description' => __('When customer becomes VIP'), 'recipients' => ['customer'], // ← Customer only ], ], ]; return rest_ensure_response($events); } ``` --- ### 3. Update Frontend to Filter Events **Update:** `admin-spa/src/routes/Settings/Notifications/Templates.tsx` ```tsx // Determine recipient type from current page const isStaffPage = window.location.pathname.includes('/staff'); const recipientType = isStaffPage ? 'staff' : 'customer'; // Filter events by recipient const filteredEvents = allEvents.filter((event: any) => { return event.recipients && event.recipients.includes(recipientType); }); // Use filteredEvents instead of allEvents