public function onLoadCustomerDetails(mixed &$query, int $id) : void

Fires while fetching the customer details.


Description

Every time the system needs to access the full details of a customer, the following code is used:

VikAppointments::getCustomer($id);

This methods always triggers an hook that can be used to extend the query to load at runtime further information of the customer, which may be stored in a different database table.

Notice that the query is always limited to 1 element, so it is not suggested to join here tables that may fetch several rows. It is needed to rely on onSetupCustomerDetails hook for this purpose.


Parameters

&$query

(mixed)  Either a query builder object or a string.

$id

(int|null)  The ID of the customer to load. NULL when the system needs to load the details of the currently logged-in user.

Return Value

None.


Example

/**
 * External plugins can attach to this hook in order to manipulate
 * the query at runtime, in example to include additional properties.
 *
 * @param   mixed    &$query  A query builder instance.
 * @param   integer  $id      The ID of the customer.
 *
 * @return  void
 */
public function onLoadCustomerDetails(&$query, $id)
{
    $dbo = JFactory::getDbo();

    // select some columns
    $query->select($dbo->qn(['tpt.column1', 'tpt.column2']));
    // join services to a third-party table
    $query->leftjoin($dbo->qn('#__myplugin_third_party_table', 'tpt') . ' ON ' . $dbo->qn('tpt.id_customer') . ' = ' . $dbo->qn('c.id'));
    // avoid duplicates
    $query->group($dbo->qn('c.id'));
}

Changelog

VersionDescription
1.7 Introduced.
Last Update: 2021-10-06 17:14
Helpful?
See Also: