/ Published in: PHP
You need a copy of your model and relations (ObjectStorage properties).
In this example there is a model Product with property ProductAddition (1:n relation).
In this example there is a model Product with property ProductAddition (1:n relation).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $productClone = $this->objectManager->create('Tx_Theext_Domain_Model_Product'); // $product = source object $productProperties = Tx_Extbase_Reflection_ObjectAccess::getAccessibleProperties($product); foreach ($productProperties as $propertyName => $propertyValue) { Tx_Extbase_Reflection_ObjectAccess::setProperty($productClone, $propertyName, $propertyValue); } // $productAdditions = ObjectStorage property $productAdditions = $product->getProductAddition(); $newStorage = $this->objectManager->get('Tx_Extbase_Persistence_ObjectStorage'); foreach ($productAdditions as $productAddition) { $productAdditionClone = $this->objectManager->create('Tx_Theext_Domain_Model_ProductAddition'); $productAdditionProperties = Tx_Extbase_Reflection_ObjectAccess::getAccessibleProperties($productAddition); foreach ($productAdditionProperties as $propertyName => $propertyValue) { Tx_Extbase_Reflection_ObjectAccess::setProperty($productAdditionClone, $propertyName, $propertyValue); } $newStorage->attach($productAdditionClone); } $productClone->setProductAddition($newStorage); // This have to be repeat for every ObjectStorage property, or write a service. ?>