Order/EventListener/OrderItemListener.php
protected function applySaleItemRecursively(Model\SaleItemInterface $item)
    {
        // If subject has changed
        if ($this->persistenceHelper->isChanged($item, 'subjectIdentity.identifier')) {
            $this->stockAssigner->detachSaleItem($item);
            $this->stockAssigner->assignSaleItem($item);
        } else {
            $this->stockAssigner->applySaleItem($item);
        }

        foreach ($item->getChildren() as $child) {
            if (
                $this->persistenceHelper->isScheduledForInsert($child)
                || (
                    $this->persistenceHelper->isScheduledForUpdate($child)
                    && $this->persistenceHelper->isChanged($child, ['quantity', 'subjectIdentity.identifier'])
                )
            ) {
                // Skip this item as the listener will be called on it.
                /** @see OrderItemListener::onUpdate() */
                continue;
            }

            $this->applySaleItemRecursively($child);
        }
    }
protected function applySaleItemRecursively(Model\SaleItemInterface $item)
    {
        // If subject has changed
        if ($this->persistenceHelper->isChanged($item, 'subjectIdentity.identifier')) {
            $this->stockAssigner->detachSaleItem($item);
            $this->stockAssigner->assignSaleItem($item);
        } else {
            $this->stockAssigner->applySaleItem($item);
        }

        foreach ($item->getChildren() as $child) {
            if (
                $this->persistenceHelper->isScheduledForInsert($child)
                || (
                    $this->persistenceHelper->isScheduledForUpdate($child)
                    && $this->persistenceHelper->isChanged($child, ['quantity', 'subjectIdentity.identifier'])
                )
            ) {
                // Skip this item as the listener will be called on it.
                /** @see OrderItemListener::onUpdate() */
                continue;
            }

            $this->applySaleItemRecursively($child);
        }
    }
Applies the sale item to stock units recursively.

@param Model\SaleItemInterface $item