Appearance
Push Notification Campaigns (Admin)
Flow ID: AD-61 | Module(s):
ecommercen/push_notifications/,application/modules/push_notifications/,application/views/admin/push_notifications/,ecommercen/settings/(Customer notifications panel) | Complexity: Medium Last Updated: 2026-11-04 — 4.129.0 resync: #985 test send reports the device count, image upload and target-field form changes, citations re-anchored; previous: 2026-10-13 — 4.127.0 resync: new doc for the push-campaign admin page and the Customer notifications settings panel (#559, PR #363)
Business Context
Two admin surfaces control customer push notifications; the sending machinery behind them is described in SY-35 Push Notifications.
- Push notifications (ecommercen Plus, Marketing): staff compose a marketing push (category
promosornews), choose who receives it, send it now or schedule it, test-send it to the shop's test customers, cancel it while unsent, and read the results. Every target is further filtered by the recipient's consent, and delivery obeys the daily cap and quiet hours. - Settings, Customer notifications: the shop-wide switch for push, the per-order-event e-mail and push behaviour and texts, the marketing cap and quiet hours, the test customers, and the retention periods.
API Reference
Admin Routes
Registered in application/config/routes.php:451-456 (each with a locale-prefixed twin): push_notifications_admin and push_notifications_admin/(:num) go to index($offset), anything else to the method named in the path.
| URL | Method | Purpose |
|---|---|---|
push_notifications_admin and push_notifications_admin/{offset} | index() (ecommercen/push_notifications/controllers/Adv_push_notifications_admin.php:53) | Paged campaign list newest first, with sent / pending / failed / opened counts |
push_notifications_admin/create | create() (:74) | Compose a campaign (GET form, POST save) |
push_notifications_admin/edit/{id} | edit() (:79) | Edit a draft or scheduled campaign; other statuses open read-only |
push_notifications_admin/cancel/{id} | cancel() (:84) | Cancel an unsent campaign; POST only, a GET just redirects to the list |
Menu entry: ecommercen Plus, Marketing, "Push notifications", roles ADVISABLE, ADMIN and MARKETING (application/config/admin_menu.php:62-68). The controller enforces the same roles itself and stops the request after rendering the 401 page (Adv_push_notifications_admin.php:38-43). The empty override class is application/modules/push_notifications/controllers/Push_notifications_admin.php.
The settings panel is part of the existing settings/notification_settings page (Adv_settings::notification_settings(), ecommercen/settings/controllers/Adv_settings.php:1071), documented in AD-13 Admin Settings. Its menu entry now also admits the ADMIN role (application/config/admin_menu.php:192-198).
Form fields (campaign)
| Field | Rule | Citation |
|---|---|---|
name | required, at most 255 chars; internal label | src/Domains/Notification/Campaign/CampaignInput.php:42-45 |
category | promos or news (marketing categories only) | :47-50 |
target | all, audience (needs audience_id) or customer (needs customer_id). The form shows only the field the chosen target uses (audience_id for audience, customer_id for customer); that field is required, and the other is hidden and cleared by script (application/views/admin/push_notifications/form.php:98-105,162-175) | :52-60 |
title_{lang}, body_{lang} | per shop language; the first language is required, others may be left empty; title at most 100, body at most 500 chars | :72-84 |
route | what a tap opens: an app path starting with a single /, or an https URL | :62-65,103-110 |
image | optional https URL with a jpg, jpeg, png, gif or webp extension (Apple needs the extension). The form also takes an uploaded JPEG or PNG (image_file, at most 1024 KB, stored under files/push/); uploadedImageUrl() turns it into a w1024 JPEG media-service rendition link that replaces the URL field. An upload that fails shows the image error upload (notifications.admin.campaigns.error.upload). The form is multipart and the preview shows the image (Adv_push_notifications_admin.php:22-28,115,119-121,202-214; form.php:29,69-71,121,177-191) | :67-70,113-122 |
scheduled_at | optional datetime-local in the future | :86-93 |
The form's action button decides what happens after a save: save (stay on the edit page), test (test send), send (queue now) (Adv_push_notifications_admin.php:146-168).
Code Flow
GET push_notifications_admin [Adv_push_notifications_admin.php:53]
|-- CampaignStore::list() + CampaignService::stats() per row [:57-60]
|-- warning banner when PushConfig::isActive() is false [:66 ; views/admin/push_notifications/list.php:3-5]
POST push_notifications_admin/create | edit/{id} [:98 form()]
|-- refuseForeignPost(): SameHostRequest on Origin / Referer vs HTTP_HOST and base_url() [call :107-111 ; definition :175-188]
|-- uploadedImageUrl() -> image link; formData() -> CampaignService::save() [:113-116 ; Campaign/CampaignService.php:35]
| CampaignInput::fromArray() validates; scheduled_at set -> status scheduled, else draft
| CampaignStore::save() in a transaction: campaign row + one _mui row per language
|-- UploadException -> form re-rendered with the image error [:119-121]
|-- ValidationException -> form re-rendered with the field errors [:122-125]
|-- afterSave(action) [:146]
test -> CampaignService::testSend() [CampaignService.php:93]
send -> CampaignService::sendNow() [:61] -> status queued, deliveries created
save -> redirect to edit
POST push_notifications_admin/cancel/{id} [:84]
|-- CampaignService::cancel() [CampaignService.php:106]Sending only queues deliveries. The DispatchNotifications job (every minute) sends them, applying consent, the daily cap and quiet hours (SY-35). A campaign that is scheduled is queued by the same job when due (CampaignService::queueDueScheduled()).
Settings panel flow
GET/POST settings/notification_settings [Adv_settings.php:1071]
|-- notificationSettingsValidation() [:1119-1188]
| push cap (natural number), quiet hours (HH:MM via callback_notificationTimeIsValid, :1196-1205),
| test customer ids (comma list of digits), retention (natural, non-zero),
| per order event: push mode in_list(off,with,instead_of_sms), title <= 100, body <= 500 per language
|-- form_validation->run($this) [:1067] (required so the callback rule resolves)
|-- SMS and OneSignal values saved only if canEditNotificationProviders() [:1073-1083,1191-1194]
|-- saveCustomerNotificationSettings() [:1207-1238] writes group NOTIFICATIONS
|-- view data from customerNotificationSettingsView() [:1240-1279]The page shows: the Firebase-key warning when FCM_SERVICE_ACCOUNT_JSON is not deployed, the push switch, daily cap, quiet hours, test customers and retention fields (application/views/admin/settings/notification_settings.php:84-166); a per-event table of e-mail switch, push mode and per-language title and body (:168-249); then, only for roles allowed to edit providers, the SMS panel (:251-338) and the OneSignal panel marked deprecated (:340-394).
Data Model
Campaigns live in notification_campaign and notification_campaign_mui; deliveries and messages in notification_delivery and notification_message. Columns are listed in SY-35 Data Model. Settings are registry rows in group NOTIFICATIONS (SY-35 Configuration).
Status lifecycle (CampaignService):
| From | To | Trigger |
|---|---|---|
| (new) | draft or scheduled | save() (scheduled when a time is given) |
draft, scheduled | queued | sendNow() or the job when due |
queued | previous status | sendNow() found no one able to receive, or queueing threw (queued_at cleared) |
draft, scheduled, queued | canceled | cancel(); also marks queued and retry deliveries skipped (canceled) |
Domain Layer
Legacy Layer
| File | Responsibility |
|---|---|
ecommercen/push_notifications/controllers/Adv_push_notifications_admin.php | The admin controller (extends Admin_c) |
application/modules/push_notifications/controllers/Push_notifications_admin.php | Empty override point |
application/views/admin/push_notifications/list.php, form.php | List and form views |
ecommercen/settings/controllers/Adv_settings.php | Settings panel validation, save and view data |
application/views/admin/settings/notification_settings.php | Settings panel markup |
Modern Domain
CampaignService, CampaignStore, CampaignInput, NotificationSettings and PushConfig in src/Domains/Notification/ (see SY-35), plus src/Support/Http/SameHostRequest.php. Audiences for the target dropdown come from audience_model->dropdown() (Adv_push_notifications_admin.php:45,136).
Configuration
Language keys are in ecommercen/language/<language>/adv_advisable_lang.php under notifications.* and the menu labels in adv_admin_menu_lang.php (admin.menu.ecommercenPlus.marketing.push.*), for all eight shipped languages. The push texts' defaults are notifications.push.<EVENT>.title and .body.
Client Extension Points
- Override
Push_notifications_admininapplication/modules/push_notifications/controllers/(or the fork's equivalent) to change the page. - A fork that overrides the
settings/notification_settingsview orAdv_settingsmisses the new controls (decision recorddocs/decisions/559-customer-notifications.md).
Business Rules
- A campaign nobody can receive is not queued. When push is off, or no opted-in device is in the target,
sendNow()returns null, the status goes back to draft or scheduled and the admin sees "no recipients" (Adv_push_notifications_admin.php:155-160;CampaignService.php:80-82). - Only draft and scheduled campaigns can be edited or saved. The form disables the fieldset otherwise (
views/admin/push_notifications/form.php:25-30) andsave()refuses with a status error (CampaignService.php:39-44). - Test send goes to the devices of the customers in
TEST_CUSTOMER_IDS, now, ignoring the daily cap and quiet hours.CampaignService::testSend()returnsint, the number of devices the message was queued for, or 0 when nobody can receive it. The flash message reports that count (notifications.admin.campaigns.test.senttakes the count as%s), and 0 showstest.none. A test send is not counted in the campaign's stats because its message carries no campaign id. The button is disabled with a hint when the list is empty, and a help line sits beside it (CampaignService.php:87-104;OutboxStore::deliveryCount()atOutboxStore.php:321;Adv_push_notifications_admin.php:148-151;form.php:133,140). - Origin check on POSTs. Save, send, test and cancel are refused (with a flash message) unless
Origin, elseReferer, names this site, becausecsrf_protectionis off platform-wide and one POST can push to every opted-in customer (Adv_push_notifications_admin.php:170-188;src/Support/Http/SameHostRequest.php). - Roles. The campaign page: ADVISABLE, ADMIN, MARKETING. On the settings page, SMS-provider and OneSignal credentials stay with ADVISABLE and DEVELOPER; other roles that can open the page manage only the notification settings (
Adv_settings.php:1201-1204). - Turning the order-confirmation e-mail off shows a warning in the settings table, because consumer law expects the contract confirmed on a durable medium (
notification_settings.php, keynotifications.admin.settings.confirmation.warning). Only the customer e-mail is switched off; the admin notification e-mail is still sent (SY-35). - Results on the list and form: sent, pending (queued + retry + sending), failed, skipped (form only), and opened with the open rate over sent. Counts start from what retention has left (
list.php:36-49;Outbox/OutboxStore.php:328-345).
Known Issues & Security Gaps
- The origin check exists only here. Other admin POSTs, including the settings page that enables push and edits the order texts, have no CSRF token and no
SameHostRequestcheck (SameHostRequestis referenced only atAdv_push_notifications_admin.php:14,177,180). - No "sent" state. A campaign stays
queuedafter its deliveries are created; completion is visible only in the counts (SY-35 Known Issues). - The campaign list runs one stats query per row.
index()callsCampaignService::stats()for each record on the page (Adv_push_notifications_admin.php:57-60), i.e. one grouped query per campaign, bounded by the page size.
Tests
No test drives the admin controller or the settings panel. The domain behaviour it calls (campaign save, send, test, cancel, scheduling, validation) is covered by tests/Integration/Domains/Notification/NotificationFlowTest.php, and the origin check by tests/Unit/Support/Http/SameHostRequestTest.php (see SY-35 Tests).
Related Flows
- SY-35 Push Notifications - the domain, REST endpoints, jobs and FCM transport behind these screens.
- AD-13 Admin Settings & Configuration - the settings area that hosts the Customer notifications page.
- AD-22 Audience & Campaigns - audiences, the "audience" target of a push campaign.
- AD-41 Customer Mail History - sent pushes are logged there with channel
PUSH.