/** * @param Product $product * @param Product $productCopy */ protected function cloneChildObjects(Product $product, Product $productCopy) { foreach ($product->getUnitPrecisions() as $unitPrecision) { $productCopy->addUnitPrecision(clone $unitPrecision); } foreach ($product->getNames() as $name) { $productCopy->addName(clone $name); } foreach ($product->getDescriptions() as $description) { $productCopy->addDescription(clone $description); } if ($imageFile = $product->getImage()) { $imageFileCopy = $this->attachmentManager->copyAttachmentFile($imageFile); $productCopy->setImage($imageFileCopy); } $attachments = $this->attachmentProvider->getEntityAttachments($product); foreach ($attachments as $attachment) { $attachmentCopy = clone $attachment; $attachmentFileCopy = $this->attachmentManager->copyAttachmentFile($attachment->getFile()); $attachmentCopy->setFile($attachmentFileCopy); $attachmentCopy->setTarget($productCopy); $this->doctrineHelper->getEntityManager($attachmentCopy)->persist($attachmentCopy); } }