Stock/Assigner/StockUnitAssigner.php
protected function createAssignmentsForQuantity(SaleItemInterface $item, $quantity)
    {
        if (0 >= $quantity) {
            return;
        }

        // Find enough available stock units
        $stockUnits = $this->sortStockUnits($this->unitResolver->findAssignable($item));

        foreach ($stockUnits as $stockUnit) {
            $assignment = $this->saleFactory->createStockAssignmentForItem($item);
            $assignment
                ->setSaleItem($item)
                ->setStockUnit($stockUnit);

            $quantity -= $this->assignmentUpdater->updateSold($assignment, $quantity);

            if (0 == $quantity) {
                return;
            }
        }

        // Remaining quantity
        if (0 < $quantity) {
            $stockUnit = $this->unitResolver->createBySubjectRelative($item);

            $assignment = $this->saleFactory->createStockAssignmentForItem($item);
            $assignment
                ->setSaleItem($item)
                ->setStockUnit($stockUnit);

            $quantity -= $this->assignmentUpdater->updateSold($assignment, $quantity);
        }

        if (0 < $quantity) {
            throw new StockLogicException(sprintf(
                'Failed to create assignments for item "%s".',
                $item->getDesignation()
            ));
        }
    }
protected function createAssignmentsForQuantity(SaleItemInterface $item, $quantity)
    {
        if (0 >= $quantity) {
            return;
        }

        // Find enough available stock units
        $stockUnits = $this->sortStockUnits($this->unitResolver->findAssignable($item));

        foreach ($stockUnits as $stockUnit) {
            $assignment = $this->saleFactory->createStockAssignmentForItem($item);
            $assignment
                ->setSaleItem($item)
                ->setStockUnit($stockUnit);

            $quantity -= $this->assignmentUpdater->updateSold($assignment, $quantity);

            if (0 == $quantity) {
                return;
            }
        }

        // Remaining quantity
        if (0 < $quantity) {
            $stockUnit = $this->unitResolver->createBySubjectRelative($item);

            $assignment = $this->saleFactory->createStockAssignmentForItem($item);
            $assignment
                ->setSaleItem($item)
                ->setStockUnit($stockUnit);

            $quantity -= $this->assignmentUpdater->updateSold($assignment, $quantity);
        }

        if (0 < $quantity) {
            throw new StockLogicException(sprintf(
                'Failed to create assignments for item "%s".',
                $item->getDesignation()
            ));
        }
    }
Creates the sale item assignments for the given quantity.

@param SaleItemInterface $item
@param float             $quantity

@throws StockLogicException If assignment creation fails.