code: private function buildSaleItemQuantities(SaleItemInterface $item, array &$quantities)
      {
          // Skip compound with only public children
          if (!($item->isCompound() && !$item->hasPrivateChildren())) {
              $quantities[$item->getId()] = [
                  'total'    => $item->getTotalQuantity(),
                  'invoiced' => $this->calculateInvoicedQuantity($item),
                  'credited' => $this->calculateCreditedQuantity($item),
              ];
          }
  
          if ($item->hasChildren()) {
              foreach ($item->getChildren() as $child) {
                  $this->buildSaleItemQuantities($child, $quantities);
              }
          }
      }
docs: Builds the sale item quantities recursively.
  
  @param SaleItemInterface $item
  @param array             $quantities