Revision: 62503
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 27, 2013 20:51 by FazzyX
Initial Code
<?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. ?>
Initial URL
Initial Description
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).
Initial Title
Extbase: Make a (deep) copy of the model
Initial Tags
php
Initial Language
PHP