Stevebauman\Inventory\Traits\InventoryTransactionTrait::reserved PHP Method

reserved() public method

If backOrder is true then the state will be set to back-order if the specified quantity is unavailable to be reserved. Otherwise it will throw an exception. If reserved is called from being checked out we'll make sure we don't take any inventory.
public reserved ( integer | float | string $quantity, boolean $backOrder = false, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$backOrder boolean
$reason string
$cost integer | float | string
    public function reserved($quantity = 0, $backOrder = false, $reason = '', $cost = 0)
    {
        /*
         * Only allow a previous state of null, opened, back ordered, and checkout
         */
        $this->validatePreviousState([null, $this::STATE_OPENED, $this::STATE_COMMERCE_BACK_ORDERED, $this::STATE_COMMERCE_CHECKOUT], $this::STATE_COMMERCE_RESERVED);
        if ($this->isCheckout()) {
            return $this->reservedFromCheckout();
        }
        $this->setAttribute('quantity', $quantity);
        $this->setAttribute('state', $this::STATE_COMMERCE_RESERVED);
        if (empty($reason)) {
            $reason = $this->getTransactionReason('reserved');
        }
        try {
            return $this->processStockTakeAndSave($quantity, 'inventory.transaction.reserved', $reason, $cost);
        } catch (NotEnoughStockException $e) {
            /*
             * Looks like there wasn't enough stock to reserve the
             * specified quantity. If backOrder is true, we'll
             * create a back order for this quantity
             */
            if ($backOrder) {
                return $this->backOrder($quantity);
            }
            throw new NotEnoughStockException($e);
        }
    }