LukePOLO\LaraCart\Traits\CartOptionsMagicMethodsTrait::__set PHP Method

__set() public method

Magic Method allows for user input to set a value inside the options array.
public __set ( $option, $value )
$option
$value
    public function __set($option, $value)
    {
        switch ($option) {
            case CartItem::ITEM_QTY:
                if (!is_numeric($value) || $value < 0) {
                    throw new InvalidQuantity('The quantity must be a valid number');
                }
                break;
            case CartItem::ITEM_PRICE:
                if (!is_numeric($value)) {
                    throw new InvalidPrice('The price must be a valid number');
                }
                break;
            case CartItem::ITEM_TAX:
                if (!empty($value) && (!is_numeric($value) || $value > 1)) {
                    throw new InvalidTaxableValue('The tax must be a float less than 1');
                }
                break;
            case CartItem::ITEM_TAXABLE:
                if (!is_bool($value) && $value != 0 && $value != 1) {
                    throw new InvalidTaxableValue('The taxable option must be a boolean');
                }
                break;
        }
        array_set($this->options, $option, $value);
        if (is_callable([$this, 'generateHash'])) {
            $this->generateHash();
        }
    }
CartOptionsMagicMethodsTrait