public function onLoadTakeawayOrderDetails( mixed &$query, int $id, mixed $langtag, array $options ) : void

Fires while creating the query used to load the details of a take-away order.


Description

External plugins can attach to this hook in order to manipulate the query at runtime, useful to include some details that are not fetched by default.


Parameters

&$query

(string|JDatabaseQuery)  Either a query string or a query builder instance.

$id

(int)  The ID of the order to load.

$langtag

(null/string)  An optional language tag for i18n support.

$options

(array)  An associative array containing a few loading options.

Return Value

None.


Example

The example below can be used to override the ordering of the query. Since the 1.8.1 version of the plugin, all the purchased products are sorted according to their custom ordering. Before this version the products were ordered according to their creation date (first purchase comes first). This example restores the behavior used before the 1.8.1 version.

/**
 * External plugins can attach to this hook in order to manipulate
 * the query at runtime, in example to alter the default ordering.
 *
 * @param   mixed  &$query   A query builder instance.
 * @param   int    $id       The ID of the order.
 * @param   mixed  $langtag  The language tag. If null, the default one will be used.
 * @param   array  $options  An array of options to be passed to the order instance.
 *
 * @return  void
 */
public function onLoadTakeawayOrderDetails(&$query, $id, $langtag, $options)
{
    $dbo = JFactory::getDbo();

    // let's load the image of the products too
    $query->select($dbo->qn('p.img_path', 'item_image'));

    // clear any other ordering
    $query->clear('order');
    // restore ordering by item ID
    $query->order($dbo->qn('i.id') . ' ASC');
}

Changelog

Version Description
1.8.4 Introduced.
Last Update: 2023-12-29 14:15
Helpful?
See Also: