public function onCalculateMaxOrdersPerInterval( int $maxarray $times, object $slot, mixed $search ) : int

Fires while fetching the maximum number of accepted orders per interval.


Description

Plugins can use this hook to change at runtime the maximum number of accepted orders per interval.

NOTE: it is possible to use $slot->ordersCount to retrieve the total number of orders that were placed for this time slot. Only the orders with the same service specified from the configuration will be counted. In case you decided to limit the orders only for delivery service, any pickup order won't be counted.


Parameters

$max

(int)  The default maximum value.

$times

(array)  The current working shift and all the related timeslots.

$slot

(object)  The current timeslot/interval.

$search

(VREAvailabilityTakeaway)  The instance used to fetch the times availability.

Return Value

Integer.  The new maximum value.


Example

The example below doubles the maximum number of accepted orders for purchases made in the week-end.

/**
 * Plugins can use this hook to change at runtime the maximum number of orders per slot. 
 *
 * @param   int     $max  The default amount.
 * @param   array   $times    The current working shift and all the related timeslots.
 * @param   object  $slot     The current timeslot.
 * @param   mixed   $search   The availability search instance.
 *
 * @return  int     The new maximum amount.
 */
public function onCalculateMaxOrdersPerInterval($max, $times, $slot, $search)
{
    // extract hours and minutes
    list($h, $m) = explode(':', $slot->value);
    // create timestamp
    $ts = VikRestaurants::createTimestamp($search->get('date'), (int) $h, (int) $m);
    // get day of the week
    $w = (int) date('w', $ts);

    // check whether the day is included between Fri and Sun
    if (in_array($w, [0, 5, 6])) {
        // double maximum amount
        $max *= 2;
    }

    return $max;
}

Changelog

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