public function onCalculateTotalDeposit( float $total, array $args ) : float

Fires while calculating the deposit amount to use for restaurant reservations.


Description

This filter can be used to alter at runtime the total deposit to leave for confirming a restaurant reservation.


Parameters

$total

(float)  The default deposit amount.

$args

(array)  An associative array containing the query arguments.

  • date - the check-in date, formatted according to the configuration of the plugin;
  • hourmin - the check-in time, always in 24H format;
  • people - the number of participants;
  • table - the table that will be assigned to the reservation.

Return Value

Float or Null. The new deposit amount. Use null to leave the default deposit.


Example

The example below uses a different deposit depending on the room that has been selected.

/**
 * This filter can be used to alter the total deposit at runtime.
 *
 * @param   float  $total    The default deposit.
 * @param   array  $args     The searched arguments.
 *
 * @return  float  The new deposit amount.
 */
public function onCalculateTotalDeposit($total, $args)
{
    $dbo = JFactory::getDbo();

    $q = $dbo->getQuery(true)
        ->select($dbo->qn('id_room'))
        ->from($dbo->qn('#__vikrestaurants_table'))
        ->where($dbo->qn('id') . ' = ' . (int) $args['table']);

    $dbo->setQuery($q, 0, 1);
    
    switch ($dbo->loadResult())
    {
        case 1:
            // leave amount as it is for "main room"
            break;

        case 2:
            // unset deposit for "garden"
            $total = 0;
            break;

        case 3:
            // double deposit for "private room"
            $total *= 2;
            break;
    }

    return $total;
}

Changelog

Version Description
1.8 Introduced.
Last Update: 2023-12-29 14:15
Helpful?