public function onCalculateMaxPreparationMeals( int $max, array $times, object $slot, mixed $search ) : int

Fires while fetching the maximum number of meals that can be prepared on each interval.


Description

Plugins can use this hook to change at runtime the maximum number of preparation meals per slot.

NOTE: it is possible to use $slot->count to retrieve the total number of preparation items that were scheduled for this time slot. Only the items with No Preparation option turned off will be counted here.


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 items that can be prepared 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 onCalculateMaxPreparationMeals($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?