public function sold($quantity = 0, $reason = '', $cost = 0)
{
/*
* If a quantity is specified, we must be using a new transaction, so we'll
* set the quantity attribute
*/
if ($quantity) {
return $this->soldAmount($quantity, $reason, $cost);
}
/*
* Make sure the previous state of the transaction was
* checked out, opened, reserved, returned/partially returned or back ordered
*/
$this->validatePreviousState([$this::STATE_OPENED, $this::STATE_COMMERCE_CHECKOUT, $this::STATE_COMMERCE_RESERVED, $this::STATE_COMMERCE_BACK_ORDERED, $this::STATE_COMMERCE_RETURNED, $this::STATE_COMMERCE_RETURNED_PARTIAL], $this::STATE_COMMERCE_SOLD);
/*
* Mark the current state sold
*/
$this->setAttribute('state', $this::STATE_COMMERCE_SOLD);
return $this->processSave('inventory.transaction.sold');
}