diff --git a/modules/themeinstallator/script.js b/modules/themeinstallator/themeinstallator.js
similarity index 98%
rename from modules/themeinstallator/script.js
rename to modules/themeinstallator/themeinstallator.js
index b2018e03b..489a18b27 100644
--- a/modules/themeinstallator/script.js
+++ b/modules/themeinstallator/themeinstallator.js
@@ -102,7 +102,4 @@ $('document').ready(function()
while (themes_id[count] != null && count < 10)
addVariation(themes_id[count++]);
}
- else
- addVariation(0);
- addDocumentation(0);
-});
\ No newline at end of file
+});
diff --git a/modules/themeinstallator/themeinstallator.php b/modules/themeinstallator/themeinstallator.php
index a48c0ac1c..9fc55e3d3 100644
--- a/modules/themeinstallator/themeinstallator.php
+++ b/modules/themeinstallator/themeinstallator.php
@@ -180,7 +180,7 @@ class ThemeInstallator extends Module
if (Tools::isSubmit('submitThemes'))
$this->selectedVariations = Tools::getValue('variation');
$_POST = @array_map('trim', $_POST);
- define('DEFAULT_COMPATIBILITY_FROM', '1.0.0.0');
+ define('DEFAULT_COMPATIBILITY_FROM', _PS_VERSION_);
define('DEFAULT_COMPATIBILITY_TO', _PS_VERSION_);
define('DEFAULT_T_VER', '1.0');
define('MAX_NAME_LENGTH', 32);
@@ -197,12 +197,15 @@ class ThemeInstallator extends Module
$this->to_disable = false;
$this->to_install = false;
$this->errors = false;
- if ($this->page == 'exportPage' AND Tools::isSubmit('exportTheme') AND ($theme = Tools::getValue('mainTheme')))
- if (!(is_dir(_PS_ALL_THEMES_DIR_.$theme) AND file_exists(_PS_ALL_THEMES_DIR_.$theme.'/index.tpl') AND $theme != 'prestashop'))
+ if ($this->page == 'exportPage' AND Tools::isSubmit('exportTheme') AND ($id_theme = Tools::getValue('mainTheme')))
+ {
+ $theme = new Theme($id_theme);
+ if (!(is_dir(_PS_ALL_THEMES_DIR_.$theme->directory) && file_exists(_PS_ALL_THEMES_DIR_.$theme->directory.'/index.tpl')))
{
$this->page = 1;
- echo parent::displayError(''.$theme.' is not a valid theme to export');
+ $this->_errors[] = Tools::displayErrors('%s is not a valid theme to export', $theme->name);
}
+ }
}
private function handleInformations()
@@ -292,7 +295,7 @@ class ThemeInstallator extends Module
public function getContentExport()
{
- $this->theme_list = scandir(_PS_ALL_THEMES_DIR_);
+ $this->theme_list = Theme::getAvailable();
$this->error = false;
self::getModuleState();
@@ -524,12 +527,9 @@ class ThemeInstallator extends Module
}
}
}
- $theme = new Theme();
- $theme->name = (string)$this->xml['name'];
- // temporary fix
- $theme->directory = $theme->name;
- $theme->add();
-
+ // note : theme was previously created at this point.
+ // It is now created during displayForm3
+ // @todo : imageType generation should be handled in a better way
if ((int)(Tools::getValue('imagesConfig')) != 3 AND self::updateImages((int)$theme->id))
$msg .= '
'.$this->l('Images have been correctly updated in database').'
';
@@ -543,20 +543,36 @@ class ThemeInstallator extends Module
private function _displayForm3()
{
+ $res = true;
+ $theme_directory = Tools::getValue('theme_directory');
$xml = simplexml_load_file(_IMPORT_FOLDER_.XMLFILENAME);
$this->xml = $xml;
if ($this->selectedVariations AND count($this->selectedVariations) > 0)
{
$ok = array();
- foreach ($this->selectedVariations as $count => $theme)
+ foreach ($this->selectedVariations as $count => $variation)
{
- if ($theme == 'prestashop')
+ if ($variation == 'prestashop')
continue;
- self::recurseCopy(_IMPORT_FOLDER_.'themes/'.$theme, _PS_ALL_THEMES_DIR_.$theme);
- if (file_exists(_PS_ALL_THEMES_DIR_.$theme))
- $ok[] = $theme;
+ $target_dir = _PS_ALL_THEMES_DIR_.$theme_directory;
+
+ if ($variation != $theme_directory)
+ $target_dir .= $variation;
+
+ $res &= self::recurseCopy(_IMPORT_FOLDER_.'themes/'.$variation, $target_dir);
+ $new_theme = new Theme();
+ $new_theme->name = (string)$this->xml['name'];
+ if( isset($this->xml['directory']))
+ $new_theme->directory = (string)$this->xml['directory'];
+ else
+ $new_theme->directory = (string)$this->xml['name'];
+ $res &= $new_theme->add();
+
+ if ($res)
+ $ok[] = $variation;
}
+
if (sizeof($ok) > 0)
{
$msg = $this->l('The following themes were successfully imported').':
'.$this->l('Uncheck this field if you do not want to install the main theme.').'
'.$var.'
+ +'.$this->l('Note: The directory of the variation will be prefixed by the theme directory.').'
' + .$var.'