transformCollection example

'states' => $lineItem->getStates(),
        ];

        $downloads = $lineItem->getExtensionOfType(OrderConverter::ORIGINAL_DOWNLOADS, OrderLineItemDownloadCollection::class);
        if ($downloads instanceof OrderLineItemDownloadCollection) {
            $data['downloads'] = array_values($downloads->map(fn (OrderLineItemDownloadEntity $download): array => ['id' => $download->getId()]));
        }

        $output[$lineItem->getId()] = array_filter($datafn ($value) => $value !== null);

        if ($lineItem->hasChildren()) {
            $output = [...$output, ...self::transformCollection($lineItem->getChildren()$id)];
        }

        return $output;
    }

    public static function transformFlatToNested(OrderLineItemCollection $lineItems): LineItemCollection
    {
        $lineItems->sortByPosition();
        $index = [];
        $root = new LineItemCollection();

        
if ($conversionContext->shouldIncludeCustomer()) {
            $customer = $context->getCustomer();
            if ($customer === null) {
                throw CartException::customerNotLoggedIn();
            }

            $data['orderCustomer'] = CustomerTransformer::transform($customer);
        }

        $data['languageId'] = $context->getLanguageId();

        $convertedLineItems = LineItemTransformer::transformCollection($cart->getLineItems());
        $shippingAddresses = [];

        if ($conversionContext->shouldIncludeDeliveries()) {
            $shippingAddresses = AddressTransformer::transformCollection($cart->getDeliveries()->getAddresses(), true);
            $data['deliveries'] = DeliveryTransformer::transformCollection(
                $cart->getDeliveries(),
                $convertedLineItems,
                $this->initialStateIdLoader->get(OrderDeliveryStates::STATE_MACHINE),
                $context->getContext(),
                $shippingAddresses
            );
        }
Home | Imprint | This part of the site doesn't use cookies.