transformFlatToNested example

$cart->addExtension(self::ORIGINAL_ID, new IdStruct($order->getId()));
        $orderNumber = $order->getOrderNumber();
        if ($orderNumber === null) {
            throw OrderException::missingOrderNumber($order->getId());
        }

        $cart->addExtension(self::ORIGINAL_ORDER_NUMBER, new IdStruct($orderNumber));
        /* NEXT-708 support: - transactions */

        $lineItems = LineItemTransformer::transformFlatToNested($order->getLineItems());

        $cart->addLineItems($lineItems);
        $cart->setDeliveries(
            $this->convertDeliveries($order->getDeliveries()$lineItems)
        );

        $event = new OrderConvertedEvent($order$cart$context);
        $this->eventDispatcher->dispatch($event);

        return $event->getConvertedCart();
    }

    
$optionTwoId = Uuid::randomHex();

        $orderLineItemCollection = new OrderLineItemCollection(
            [
                $this->buildOrderLineItemEntity($containerId, LineItem::CUSTOM_LINE_ITEM_TYPE, null, 3),
                $this->buildOrderLineItemEntity($productId, LineItem::PRODUCT_LINE_ITEM_TYPE, $containerId, 3),
                $this->buildOrderLineItemEntity($optionOneId, LineItem::CUSTOM_LINE_ITEM_TYPE, $containerId, 3),
                $this->buildOrderLineItemEntity($optionTwoId, LineItem::CUSTOM_LINE_ITEM_TYPE, $containerId, 3),
            ]
        );

        $nestedCollection = LineItemTransformer::transformFlatToNested($orderLineItemCollection);
        static::assertCount(1, $nestedCollection);

        $lineItem = $nestedCollection->first();
        static::assertInstanceOf(LineItem::class$lineItem);
        static::assertSame(3, $lineItem->getQuantity());

        $childrenCollection = $lineItem->getChildren();
        static::assertCount(3, $childrenCollection);

        $productCollection = $childrenCollection->filterType(LineItem::PRODUCT_LINE_ITEM_TYPE);
        static::assertCount(1, $productCollection);

        
Home | Imprint | This part of the site doesn't use cookies.