'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($data,
fn ($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();