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

        if ($this->contextHasGroup(['Default', 'OrderInvoice', 'Search'], $context)) {
            $sale = $invoice->getSale();

            $data = array_replace($data, [
                'number'      => $invoice->getNumber(),
                'company'     => $sale->getCompany(),
                'email'       => $sale->getEmail(),
                'first_name'  => $sale->getFirstName(),
                'last_name'   => $sale->getLastName(),
                'type'        => $invoice->getType(),
                'method'      => $invoice->getPaymentMethod()->getName(),
                'description' => $invoice->getDescription(),
                'comment'     => $invoice->getComment(),
            ]);
        } elseif ($this->contextHasGroup(['Summary'], $context)) {
            $items = [];

            foreach ($invoice->getLines() as $item) {
                $items[] = $this->normalizeObject($item, $format, $context);
            }

            $data = array_replace($data, [
                'items'       => $items,
                'description' => $invoice->getDescription(),
                'comment'     => $invoice->getComment(),
            ]);
        }

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

        if ($this->contextHasGroup(['Default', 'OrderInvoice', 'Search'], $context)) {
            $sale = $invoice->getSale();

            $data = array_replace($data, [
                'number'      => $invoice->getNumber(),
                'company'     => $sale->getCompany(),
                'email'       => $sale->getEmail(),
                'first_name'  => $sale->getFirstName(),
                'last_name'   => $sale->getLastName(),
                'type'        => $invoice->getType(),
                'method'      => $invoice->getPaymentMethod()->getName(),
                'description' => $invoice->getDescription(),
                'comment'     => $invoice->getComment(),
            ]);
        } elseif ($this->contextHasGroup(['Summary'], $context)) {
            $items = [];

            foreach ($invoice->getLines() as $item) {
                $items[] = $this->normalizeObject($item, $format, $context);
            }

            $data = array_replace($data, [
                'items'       => $items,
                'description' => $invoice->getDescription(),
                'comment'     => $invoice->getComment(),
            ]);
        }

        return $data;
    }
public function normalize ( $ invoice , $ format = null , array $ context = [ ] ) { $ data = parent :: normalize ( $ invoice , $ format , $ context ) ; if ( $ this -> contextHasGroup ( [ 'Default' , 'OrderInvoice' , 'Search' ] , $ context ) ) { $ sale = $ invoice -> getSale ( ) ; $ data = array_replace ( $ data , [ 'number' => $ invoice -> getNumber ( ) , 'company' => $ sale -> getCompany ( ) , 'email' => $ sale -> getEmail ( ) , 'first_name' => $ sale -> getFirstName ( ) , 'last_name' => $ sale -> getLastName ( ) , 'type' => $ invoice -> getType ( ) , 'method' => $ invoice -> getPaymentMethod ( ) -> getName ( ) , 'description' => $ invoice -> getDescription ( ) , 'comment' => $ invoice -> getComment ( ) , ] ) ; } elseif ( $ this -> contextHasGroup ( [ 'Summary' ] , $ context ) ) { $ items = [ ] ; foreach ( $ invoice -> getLines ( ) as $ item ) { $ items [ ] = $ this -> normalizeObject ( $ item , $ format , $ context ) ; } $ data = array_replace ( $ data , [ 'items' => $ items , 'description' => $ invoice -> getDescription ( ) , 'comment' => $ invoice -> getComment ( ) , ] ) ; } return $ data ; }
@inheritdoc

@param InvoiceInterface $invoice
@inheritdoc