Your cart is empty!
Validate Mandatory Compliance
public function onValidateMandatoryPackageCompliance(VAPCartItem $item, VAPCart $cart) : bool|null
Fires while checking whether the package purchase is mandatory for the booked service.
Description
This hook can be used to check whether the service we are going to book requires the purchase of a package before proceeding.
NOTE: this hook doesn't fire in case the global Mandatory Purchase setting is disabled.
Parameters
- $item
-
(VAPCartItem) The cart item to validate.
- $cart
-
(VAPCart) The current cart instance.
Return Value
Boolean. By returning TRUE, the system will immediately mark the selected service as bookable, without checking the existing package purchases. By returning FALSE, the system will block the booking process for the selected service. By returning NULL, the system will proceed with the standard validation.
Example
This example skips the mandatory purchase of the packages for all the services that don't belong to a specific group ID.
/**
* Checks whether a cart item (service) is compliant with the mandatory
* package setting. Triggers only when globally enabled.
*
* @param VAPCartItem $item The cart item to validate.
* @param VAPCart $cart The cart instance.
*
* @return bool True to ignore the validation, false in case
* the item is not compliant, null to fallback
* to the default validation.
*/
public function onValidateMandatoryPackageCompliance($item, $cart)
{
// fetch service ID from item details
$serviceId = $item->getServiceID();
// fetch service details
$service = JModelVAP::getInstance('service')->getItem($serviceID);
// define here the list of group IDs owning services with
// mandatory purchase of packages
$groupsWithMandatoryPurchase = [
1, 2, 3
];
// in case the service group is NOT inside our list, ignore
// mandatory purchase validation
if (!in_array($service->id_group, $groupsWithMandatoryPurchase)) {
return true;
}
// return NULL to preserve normal behavior for services requiring
// the mandatory purchase of the packages
return null;
}
Changelog
| Version | Description |
|---|---|
| 1.7.4 | Introduced. |
Last Update: 2 weeks ago.
Helpful?