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);
}
}