public function onValidateZipCode( DeliveryQuery $query, Area $area ) : bool

Fires while validating a ZIP code against the configuration of a specific delivery area.


Description

It is possible to use this hook to enhance or change the default algorithm while checking whether a specific ZIP code is allowed or not.

You can access the ZIP code of the customer by using the code below:

// extract ZIP code from search query
$zipCode = $query->getZipCode();

It is possible to access the list of configured ZIP codes through the code below:

/** @var object[] */
$codes = $area->get('codes', []);

The array contains only objects holding the following properties: from (the initial range of the ZIP code), to (the ending range) and published (whether the range should be considered or not).


Parameters

$query

(DeliveryQuery)  The object holding the information about the address of the customer. This object is part of the E4J\VikRestaurants\DeliveryArea namespace.

$area

(Area)  The object holding the information about the configured delivery area. This object is part of the E4J\VikRestaurants\DeliveryArea namespace.

Return Value

Boolean or Null. True to immediately accept the ZIP code, false to deny the ZIP code validation., null to rely on the default algorithm.


Example

/**
 * It is possible to use this hook to enhance or change the default algorithm
 * while checking whether a specific ZIP code is allowed or not.
 *
 * @param   DeliveryQuery  $query  The delivery query,
 * @param   Area           $area   The instance used to validate an address by zip code.
 *
 *
 * @return  bool|null  Returns true to accept the ZIP code. Return false to deny the
 *                     ZIP Code. Return null to rely on the default algorithm.
 */
public function onValidateZipCode($query, $area)
{
    return null;
}

Changelog

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