Reputation: 43
I have a existing project developed on pimcore 3. I am facing a challenge while localizing the existing fields of a class, as on moving a field into the localized field container means the loss of data from the field in all objects using this class. I don't want to loss that data and instead wanted that data to be moved to english language of that localizedfield container.
Let's say I have a class "test" with below fields:
Let's say now I want to localize below 3 fields for English , French and German.
But I don't want my existing data to be lost, instead I want the english language of field of that localization to be filled up with existing data.
Thanks in advance.
Upvotes: 3
Views: 572
Reputation: 1276
Unfortunately this is not completely straightforward. In the most simple case you should write two simple scripts.
Follow this workflow:
After you copied do this:
Sample script (NOT TESTED):
// First run copyValueFromFieldsToTempFieldsAction(),
// then move the fields into localized field,
// afterwards run copyValueFromTempFieldsToFieldsAction()
// in the end remove temp fields
public function copyValueFromFieldsToTempFieldsAction(){
$this->disableViewAutoRender();
$objectList = new \Pimcore\Model\YourObject\Listing();
//$object_list->setObjectTypes(array(Object_Abstract::OBJECT_TYPE_VARIANT));
/* @var $object Object_PrdktResetkeNaZalogi */
foreach($objectList as $object){
$object->setNameTemp($object->getName());
$object->setDescTemp($object->getTemp());
$object->setCategoryTemp($object->getCategory());
$object->save();
}
}
public function copyValueFromTempFieldsToFieldsAction(){
$this->disableViewAutoRender();
$objectList = new \Pimcore\Model\YourObject\Listing();
//$object_list->setObjectTypes(array(Object_Abstract::OBJECT_TYPE_VARIANT));
/* @var $object Object_PrdktResetkeNaZalogi */
foreach($objectList as $object){
$object->setTemp($object->getNameTemp());
$object->setDesc($object->getTemp());
$object->setCategory($object->getCategorTemp());
$object->save();
}
}
Upvotes: 3