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

sold() public method

If no quantity is specified and the previous state was not in checkout, reserved, back ordered, returned or returned partial, this will throw an exception.
public sold ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string
    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');
    }