Developer notes
Overview · Installation · Configuration · Usage · FAQ
Where events come from
Section titled “Where events come from”| Event | Source (CS-Cart 4.17.2 – 4.21.2) |
|---|---|
| New order | PHP hook change_order_status_post, when the order leaves N (incomplete) for any status other than N/T; parent orders are skipped. |
| Order paid | Same hook, when the new status is in Paid statuses and the old one was not. |
| Return request | Pre-controller rma.pre.php (storefront and panel) for POST rma.add_return: after the request, the newest return of that order created in this request is stored (core has no hook there). |
| Low stock | PHP hook update_product_amount_post, when the stock crosses the threshold downwards (tracking not disabled). |
| New message | Pre-controller vendor_communication.pre.php for POST post_message / create_thread: after the request, the new message is stored. Receiver: customer → vendor (Multi-Vendor) or administrator (CS-Cart); vendor → administrator; administrator → vendor. |
Limits:
- Orders placed through the REST API, the storefront, the admin panel or payment callbacks are captured (status hook). Orders, products or stock written straight into the database (imports, external scripts) are not.
- An edited order (core sets it to Incomplete and back) is never announced again; an order placed before installation or more than 24 hours before it left Incomplete is not announced as new.
- Low stock fires only when stock changes through
fn_update_product_amount()(orders, returns, status changes). A stock edit on the product page, an import or the REST API gives no alert. In CS-Cart Ultimate, a shared product’s alert goes to the storefront that owns the product. - Returns created through the REST API or admin bulk tools, messages sent through the API or the vendor mobile app, and administrator bulk messages to several vendors (
m_post_message, or one thread per vendor from create thread for all vendors: only the last thread is announced) are not captured. - The poll writes a small timestamp into the back-office session (4-second throttle) on each check; core saves the session on every request anyway.
Tables
Section titled “Tables”| Table | Columns |
|---|---|
cscart_kv_oal_events |
event_id (PK), type (O, P, R, S, M), company_id, audience (‘’ both panels, A administrator, V vendor), object_id, dedupe (unique: one new / paid event per order, one per return and message), created_at, data (JSON, max 1000 bytes). Keys (company_id, event_id) and created_at. |
cscart_kv_oal_prefs |
user_id (PK), data (JSON preferences), updated_at. Removed with the user. |
Events of a deleted company are removed with it; older events are pruned on insert (retention setting).
Poll endpoint
Section titled “Poll endpoint”GET admin.php|vendor.php?dispatch=kv_order_alerts.poll&since=<event id> answers JSON:
{"ok": true, "events": [{"id": 41, "type": "O", "obj": 1203, "ts": 1794400000, "d": {"n": 1203, "t": "$129.50", "st": "Open"}}], "last": 41, "more": false, "interval": 20}- Signed-in back-office users with the View order alerts privilege only;
since=0returns the newest id the user may see. - One query:
event_id > sinceplus the viewer scope (company_id= the vendor or the storefront picked in the panel,audience, allowed types),ORDER BY event_id LIMIT 50. The allowed types are worked out from the privileges when a page is displayed and kept in the session for 10 minutes. - A request less than 4 seconds after the previous one of the same session is answered without a query (
retry). off: truewhen the add-on is switched off, unlicensed or the user has no alert types.
Browser script
Section titled “Browser script”js/addons/kv_order_alerts/alerts.js (ES5 + jQuery). Configuration: Tygh.kvOrderAlerts, printed by the hook index:scripts only for users who get alerts. One tab per user is the leader (localStorage key kv_oal_<key>_leader); it polls and passes the events to the other tabs through the storage event. Sounds are synthesized with the Web Audio API. window.KvOrderAlerts.play('<sound>', <volume>) plays a sound.
Bell slots: hook menu:notification_center (4.17) and menu:top_bar_right (4.18+); a floating bell is added when a custom admin theme has neither.
| Hook | Purpose |
|---|---|
change_order_status_post |
New order and paid events |
update_product_amount_post |
Low stock events |
dispatch_before_display |
Page configuration of the bell (back office only) |
post_delete_user |
Removes the user’s preferences |
delete_company |
Removes the company’s events |
File map
Section titled “File map”| Path | Purpose |
|---|---|
app/addons/kv_order_alerts/addon.xml |
Settings, tables, privilege |
app/addons/kv_order_alerts/func.php |
Hook handlers, settings variants |
Tygh/Addons/KvOrderAlerts/Config.php |
Settings with safe defaults, licence gate (isOn()) |
Tygh/Addons/KvOrderAlerts/Recorder.php |
Turns hooks and requests into events |
Tygh/Addons/KvOrderAlerts/Events.php |
Event log: insert, prune, scoped reads, payload |
Tygh/Addons/KvOrderAlerts/Access.php |
Viewer scope: panel side, company, allowed types |
Tygh/Addons/KvOrderAlerts/Prefs.php |
Personal preferences |
Tygh/Addons/KvOrderAlerts/Panel.php |
Browser configuration and texts |
controllers/backend/kv_order_alerts.php |
Poll, preferences page, save |
controllers/{backend,frontend}/rma.pre.php, vendor_communication.pre.php |
Return and message events |
schemas/permissions/*.post.php, schemas/menu/menu.post.php |
Privilege, vendor access, menu item |
design/backend/templates/addons/kv_order_alerts/ |
Bell, preferences page, hook files, licence UI |
design/backend/css/addons/kv_order_alerts/alerts.less |
Styles (built on the admin LESS variables) |
License/, Upgrade/Synchronizer.php |
Licence check and self-healing upgrades (generated) |