Events and jobs
The events the B2B plugins emit and the scheduled jobs they run.
The B2B plugins emit events on the backend's event bus, next to the core commerce events. Subscribe to them in your own plugin to react to company changes.
Payloads
Payloads carry IDs only. Read the current state from the API when you handle an event. New fields may be added within a version, so ignore fields you don't know. Each event has a JSON Schema in the repo under docs/specs/events.
Company events
| Event | Payload | When |
|---|---|---|
company.created | id | A merchant created a company, or a buyer signed one up. |
company.updated | id | A company's details, status, or settings overrides changed, by a merchant or a buyer. |
company.approved | id | A pending company became active. company.updated is emitted too. |
company.deleted | id | A company was deleted. employee.removed is emitted for each employee too. |
employee.created | id, company_id | A customer became an active employee, including the owner at signup. |
employee.updated | id, company_id | An employee's role changed. |
employee.removed | id, company_id | An employee was removed, their company was deleted, or their customer account was deleted. The customer account stays in the first two cases. |
Address changes emit no events.
{ "id": "emp_01JB2X7QA1", "company_id": "comp_01JB2X7Q8R" }Settings events
b2b-setting.updated carries keys, the setting keys that changed. It is in the contract for POST /admin/b2b-settings, which isn't served yet, so nothing emits it today.
Scheduled jobs
| Job | Schedule | What it does |
|---|---|---|
reconcile-order-companies | Daily at 03:00 (cron 0 3 * * *) | Links any order from a cart completed in the last 48 hours that still has no company. A safety net for the order.placed subscriber. |
The job only adds missing links. It never changes an order that already has a company. Set COMPANY_ORDER_RECONCILE=false in the backend's environment to turn it off. See Carts and checkout for how orders get their company.