public function checkout($quantity = 0, $reason = '', $cost = 0)
{
/*
* Only allow a transaction that has a previous state of
* null, opened and reserved to use the checkout function
*/
$this->validatePreviousState([null, $this::STATE_OPENED, $this::STATE_COMMERCE_RESERVED], $this::STATE_COMMERCE_CHECKOUT);
if ($this->isReservation()) {
return $this->checkoutFromReserved();
}
$this->setAttribute('quantity', $quantity);
$this->setAttribute('state', $this::STATE_COMMERCE_CHECKOUT);
if (empty($reason)) {
$reason = $this->getTransactionReason('checkout');
}
return $this->processStockTakeAndSave($quantity, 'inventory.transaction.checkout', $reason, $cost);
}