public function onAddOptionCart(VAPCartItem $item, VAPCartOption &$option) : bool

Fires before adding a new option to a specific item (service).


Description

Trigger hook before adding a new option to a service.

It is possible to use this hook to prevent the customers from adding specific options into the cart or to manipulate the details of the options at runtime.

It is possible to use VAPCart::getInstance() to access all the items stored within the cart.


Parameters

$item

(VAPCartItem)  The item to which the option should be added.

&$option

(VAPCartOption)  The option to assign.

Return Value

Boolean. True to assign the option to the service, false to discard it.


Example

The following example increments the maximum quantity of the options for registered users.

/**
 * Trigger event before adding an option to the cart item.
 *
 * @param   mixed    $item     The cart item object.
 * @param   mixed    &$option  The item option object.
 *
 * @return  boolean  True to assign the option, false otherwise.
 */
public function onAddOptionCart($item, &$option)
{
    if (VikAppointments::isUserLogged())
    {
        // copy the option details into a new instance because VAPCartOption
        // class doesn't provide a setter to change the maximum quantity
        $option = new VAPCartOption(
            $option->getID(),
            $option->getVariationID(),
            $option->getName(),
            $option->getPrice(),
            $option->getMaxQuantity() * 2,
            $option->isRequired(),
            $option->getQuantity()
        );
    }

    return true;
}

Changelog

VersionDescription
1.6 Introduced.
Last Update: 2021-10-06 16:25
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information