I'm trying to import data from another database using locales, but am having trouble saving the other locale after the primary locale is saved.
foreach($row as $data) {
$entry = new EntryModel();
$entry->sectionId = 1;
$entry->typeId = 1;
$entry->authorId = 1;
$entry->enabled = true;
$entry->locale = "en";
$entry->getContent()->setAttributes(array(
'description' => $data["description-en"],
));
$success = craft()->entries->saveEntry($entry);
if ($success)
{
ImportPlugin::log('Successfully saved entry "'.$entry->id.'"', LogLevel::Info);
$entryEs = craft()->entries->getEntryById($entry->id, "es");
$entryEs->getContent()->setAttributes(array(
'description' => $data["description-es"],
));
// **** The following doesn't work for some reason ****
craft()->entries->saveEntry($entryEs);
};
}
The primary entry saves fine and if I dump vars I can see that both $entry.id
and $entryEs
exist and are formatted as expected — but it doesn't save.
Is it perhaps being overwritten (or ignored) as the content from the primary locale is being copied to the other locales in the background? What's the recommended way to save multiple locales?
$entry->locale = "en";
and you are trying to retrieve an entry by asking for the id 'es' in this line$entryEs = craft()->entries->getEntryById($entry->id, "es");
– Ben Parizek Feb 20 '15 at 5:50