Skip to content

Listen to events

ClientFence fires an event at each important step, such as a new order or a payment. A module listens to an event with a public static method of its service that is named after the event and takes a \ClientFence\Event.

public static function onAfterClientOrderCreate(\ClientFence\Event $event): void
{
$params = $event->getParameters();
$event->getDi()['logger']->info('Hello: client #%s placed order #%s', $params['client_id'], $params['id']);
}

This line shows in Activity → System Activity after each order. $event->getDi() gives the same container as the service’s $this->di.

ClientFence connects the listeners when you activate the module, and again on each cron run. After adding a listener to an active module, wait for the next cron run or deactivate and activate the module. Extensions → Overview → Hooks lists every connected listener (see Inspect widgets and event hooks).

Most events have a Before and an After form: a Before listener runs first and can stop the action by throwing an exception.

Event When Parameters
onAfterClientSignUp A client creates an account. id, email, first_name, last_name, ip
onAfterAdminClientCreate Staff create a client. The form fields (look the client up by email)
onAfterClientOrderCreate A client checks out. id (order), client_id, ip
onAfterAdminOrderActivate An order’s service is set up. id (order)
onAfterAdminOrderRenew A service is renewed. id (order)
onAfterAdminOrderSuspend, onAfterAdminOrderUnsuspend A service is suspended or unsuspended. id (order)
onAfterAdminOrderCancel A service is cancelled. id (order)
onAfterAdminInvoicePaymentReceived An invoice is paid in full. id (invoice)
onAfterAdminInvoiceRefund An invoice is refunded. id (invoice)
onEventBeforeInvoiceIsDue, onEventAfterInvoiceIsDue Cron’s invoice reminders. id (invoice), days_left or days_passed
onAfterClientOpenTicket, onAfterAdminOpenTicket A ticket is opened. id (ticket)
onAfterClientReplyTicket, onAfterAdminReplyTicket A ticket gets a reply. id (ticket)
onAfterClientLogin A client signs in. id, ip
onAfterAdminCronRun Each cron run ends. None

To find every event, search the code for 'event' =>: each match fires one and shows its parameters.