Bridge/Symfony/Serializer/Normalizer/SaleItemNormalizer.php
public function normalize($item, $format = null, array $context = [])
    {
        $data = [];

        if ($this->contextHasGroup('Summary', $context)) {
            $children = [];
            foreach ($item->getChildren() as $child) {
                $children[] = $this->normalize($child, $format, $context);
            }

            $sale = $item->getSale();

            $shipmentData = [
                'shipped'   => null,
                'returned'  => null,
                'available' => null,
                'in_stock'  => null,
            ];
            if ($sale instanceof ShipmentSubjectInterface) {
                if ($item->isCompound()) {
                    foreach ($children as $child) {
                        $quantity = $child['quantity'];
                        foreach (['shipped', 'returned', 'available', 'in_stock'] as $key) {
                            $qty = $child[$key] / $quantity;
                            if (null === $shipmentData[$key] || $shipmentData[$key] > $qty) {
                                $shipmentData[$key] = $qty;
                            }
                        }
                    }
                } else {
                    $shipmentData = [
                        'shipped'   => $this->shipmentCalculator->calculateShippedQuantity($item),
                        'returned'  => $this->shipmentCalculator->calculateReturnedQuantity($item),
                        'available' => $this->shipmentCalculator->calculateAvailableQuantity($item),
                        'in_stock'  => $this->getInStock($item),
                    ];
                }
            }

            $invoiceData = ['invoiced' => 0, 'credited' => 0];
            if ($sale instanceof InvoiceSubjectInterface) {
                $invoiceData = [
                    'invoiced' => $this->invoiceCalculator->calculateInvoicedQuantity($item),
                    'credited' => $this->invoiceCalculator->calculateCreditedQuantity($item),
                ];
            }

            $data = array_replace($data, [
                'designation'    => $item->getDesignation(),
                'reference'      => $item->getReference(),
                'quantity'       => $item->getQuantity(),
                'total_quantity' => $item->getTotalQuantity(),
                'private'        => $item->isPrivate(),
                //'compound'         => $item->isCompound(),
                //'private_children' => $item->hasPrivateChildren(),
                'children'       => $children,
            ], $shipmentData, $invoiceData);
        }

        return $data;
    }
public function normalize($item, $format = null, array $context = [])
    {
        $data = [];

        if ($this->contextHasGroup('Summary', $context)) {
            $children = [];
            foreach ($item->getChildren() as $child) {
                $children[] = $this->normalize($child, $format, $context);
            }

            $sale = $item->getSale();

            $shipmentData = [
                'shipped'   => null,
                'returned'  => null,
                'available' => null,
                'in_stock'  => null,
            ];
            if ($sale instanceof ShipmentSubjectInterface) {
                if ($item->isCompound()) {
                    foreach ($children as $child) {
                        $quantity = $child['quantity'];
                        foreach (['shipped', 'returned', 'available', 'in_stock'] as $key) {
                            $qty = $child[$key] / $quantity;
                            if (null === $shipmentData[$key] || $shipmentData[$key] > $qty) {
                                $shipmentData[$key] = $qty;
                            }
                        }
                    }
                } else {
                    $shipmentData = [
                        'shipped'   => $this->shipmentCalculator->calculateShippedQuantity($item),
                        'returned'  => $this->shipmentCalculator->calculateReturnedQuantity($item),
                        'available' => $this->shipmentCalculator->calculateAvailableQuantity($item),
                        'in_stock'  => $this->getInStock($item),
                    ];
                }
            }

            $invoiceData = ['invoiced' => 0, 'credited' => 0];
            if ($sale instanceof InvoiceSubjectInterface) {
                $invoiceData = [
                    'invoiced' => $this->invoiceCalculator->calculateInvoicedQuantity($item),
                    'credited' => $this->invoiceCalculator->calculateCreditedQuantity($item),
                ];
            }

            $data = array_replace($data, [
                'designation'    => $item->getDesignation(),
                'reference'      => $item->getReference(),
                'quantity'       => $item->getQuantity(),
                'total_quantity' => $item->getTotalQuantity(),
                'private'        => $item->isPrivate(),
                //'compound'         => $item->isCompound(),
                //'private_children' => $item->hasPrivateChildren(),
                'children'       => $children,
            ], $shipmentData, $invoiceData);
        }

        return $data;
    }
@inheritdoc

@param SaleItemInterface $item