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

        if ($this->contextHasGroup(['StockView', 'StockAssignment'], $context)) {
            $formatter = $this->getFormatter();

            $data = array_replace($data, [
                'sold'    => $formatter->number($assignment->getSoldQuantity()),
                'shipped' => $formatter->number($assignment->getShippedQuantity()),
            ]);

            if ($this->contextHasGroup('StockView', $context)) {
                $sale = $assignment->getSaleItem()->getSale();
                $data['order_id'] = $sale->getId();
                $data['preparation'] =
                    $sale instanceof ShipmentSubjectInterface &&
                    $sale->getShipmentState() === ShipmentStates::STATE_PREPARATION;
            }

            if ($this->contextHasGroup('StockAssignment', $context)) {
                $data['unit'] = $this->normalizeObject($assignment->getStockUnit(), $format, $context);
            }
        }

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

        if ($this->contextHasGroup(['StockView', 'StockAssignment'], $context)) {
            $formatter = $this->getFormatter();

            $data = array_replace($data, [
                'sold'    => $formatter->number($assignment->getSoldQuantity()),
                'shipped' => $formatter->number($assignment->getShippedQuantity()),
            ]);

            if ($this->contextHasGroup('StockView', $context)) {
                $sale = $assignment->getSaleItem()->getSale();
                $data['order_id'] = $sale->getId();
                $data['preparation'] =
                    $sale instanceof ShipmentSubjectInterface &&
                    $sale->getShipmentState() === ShipmentStates::STATE_PREPARATION;
            }

            if ($this->contextHasGroup('StockAssignment', $context)) {
                $data['unit'] = $this->normalizeObject($assignment->getStockUnit(), $format, $context);
            }
        }

        return $data;
    }
@inheritdoc

@param StockAssignmentInterface $assignment