Skip to content

Instantly share code, notes, and snippets.

@twesolowski
Last active March 1, 2018 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twesolowski/14bb2bf3e00872915a03 to your computer and use it in GitHub Desktop.
Save twesolowski/14bb2bf3e00872915a03 to your computer and use it in GitHub Desktop.
Prestashop country translation importer
<?php
/*
* example usage: php parse.php --file="de\data\country.xml" --lang=de --prefix=ps_
* generates imports country translations in DE lang
*/
$options = getopt(null, array(
"file:", // Required
"prefix::", // Optional
"lang::" // Required
));
$file = isset($options['file']) or die("No file");
$lang = isset($options['lang']) or die("No lang");
$file = $options['file'];
$lang = $options['lang'];
$prefix = isset($options['prefix']) ? $options['prefix'] : "ps_";
file_exists($file) or die("File $file doesn't exist");
$xml=simplexml_load_file($file) or die("Error: Cannot create object");
//var_dump($xml);
foreach($xml as $element){
echo 'REPLACE INTO '.$prefix.'country_lang SET id_country= (SELECT id_country FROM '.$prefix.'country WHERE iso_code="'.$element->attributes()->id.'"), id_lang=(SELECT id_lang FROM '.$prefix.'lang WHERE iso_code="'.$lang.'"), name="'.$element->name.'"; ';
echo "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment