Your cart is empty!
Load Area
public function onLoadDeliveryArea( string $type ) : string
Fires while creating a new instance for the provided delivery area type.
Description
Trigger hook to allow external plugins to include new types of delivery areas that might have been implemented out of this project.
Plugins must include here the file holding the class of the area type. The resulting class must inherit the E4J\VikRestaurants\DeliveryArea\Area
declaration, otherwise it will be ignored.
Parameters
- $type
-
(string) The delivery area type.
Parameters
String. A custom classname that should be used to handle a specific type of delivery areas.
Example
The following examples loads a custom delivery area type from the types subfolder.
/**
* Trigger hook to allow external plugins to include new types of delivery
* areas that might have been implemented out of this project. Plugins must
* include here the file holding the class of the area type.
*
* @param string $type The requested delivery area type.
*
* @return string The classname used to load the delivery area type instance.
*/
public function onLoadDeliveryArea($type)
{
if ($type === 'custom') {
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'types' . DIRECTORY_SEPARATOR . 'custom.php';
return 'CustomDeliveryAreaType';
}
}
Here's how a custom delivery area type should be implemented.
use E4J\VikRestaurants\DeliveryArea\Area;
use E4J\VikRestaurants\DeliveryArea\DeliveryQuery;
class CustomDeliveryAreaType extends Area
{
/**
* Returns the name of the area type.
*
* @return string
*/
public function getType()
{
return 'Custom';
}
/**
* Checks whether the provided delivery query can be covered by this area.
*
* @param DeliveryQuery $query
*
* @return bool True if supported, false otherwise.
*/
public function canAccept(DeliveryQuery $query)
{
/** @var null|object (latitude, longitude) */
$coordinates = $query->getCoordinates();
/** @var null|string */
$address = $query->getAddress();
/** @var null|string */
$city = $query->getCity();
/** @var null|string */
$zip = $query->getZipCode();
// to see all the registered components
echo json_encode($query, JSON_PRETTY_PRINT);
/**
* @todo check whether the delivery query is acceptable
*/
return false;
}
/**
* Fires when the model is going to save the delivery area.
* Children classes can overwrite this method to manipulate the
* contents and the attributes.
*
* @param array &$src The data to bind.
* @param mixed $model The form model.
*
* @return bool True on success, false otherwise.
*/
public function onSave(array &$src, $model)
{
return true;
}
}
Changelog
Version | Description |
---|---|
1.9 | Introduced. |
Last Update: 2023-12-29 14:15
Helpful?