diff --git a/admin-dev/themes/default/template/controllers/import/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/import/helpers/form/form.tpl
index 09a50329f..181508404 100644
--- a/admin-dev/themes/default/template/controllers/import/helpers/form/form.tpl
+++ b/admin-dev/themes/default/template/controllers/import/helpers/form/form.tpl
@@ -77,6 +77,7 @@
{l s='Sample Addresses file'}
{l s='Sample Manufacturers file'}
{l s='Sample Suppliers file'}
+ {l s='Sample Alias file'}
{if $PS_ADVANCED_STOCK_MANAGEMENT}
{l s='Supply Orders sample file'}
{l s='Supply Orders Details sample file'}
@@ -203,12 +204,12 @@
});
$("select#entity").change(function(){
- if ($("#entity > option:selected").val() == 7 || $("#entity > option:selected").val() == 8)
+ if ($("#entity > option:selected").val() == 8 || $("#entity > option:selected").val() == 9)
$("label[for=truncate],#truncate").hide();
else
$("label[for=truncate],#truncate").show();
- if ($("#entity > option:selected").val() == 8)
+ if ($("#entity > option:selected").val() == 9)
{
$(".import_supply_orders_details").show();
$('input[name=multiple_value_separator]').val('|');
@@ -226,7 +227,7 @@
$(".import_products_categories, label[for=regenerate], #regenerate").show();
else
$(".import_products_categories, label[for=regenerate], #regenerate").hide();
- if ($("#entity > option:selected").val() == 0 || $("#entity > option:selected").val() == 1 || $("#entity > option:selected").val() == 3 || $("#entity > option:selected").val() == 5 || $("#entity > option:selected").val() == 6)
+ if ($("#entity > option:selected").val() == 0 || $("#entity > option:selected").val() == 1 || $("#entity > option:selected").val() == 3 || $("#entity > option:selected").val() == 5 || $("#entity > option:selected").val() == 6 || $("#entity > option:selected").val() == 7)
$("label[for=forceIDs], #forceIDs").show();
else
$("label[for=forceIDs], #forceIDs").hide();
@@ -260,4 +261,4 @@
});
};
});
-
\ No newline at end of file
+
diff --git a/classes/Alias.php b/classes/Alias.php
index b6fda0903..386aa741d 100644
--- a/classes/Alias.php
+++ b/classes/Alias.php
@@ -124,5 +124,21 @@ class AliasCore extends ObjectModel
{
return Configuration::get('PS_ALIAS_FEATURE_ACTIVE');
}
+
+ /**
+ * This method is allow to know if a alias exist for AdminImportController
+ * @since 1.5.6.0
+ * @return bool
+ */
+ public static function aliasExists($id_alias)
+ {
+ $row = Db::getInstance()->getRow('
+ SELECT `id_alias`
+ FROM '._DB_PREFIX_.'alias a
+ WHERE a.`id_alias` = '.(int)$id_alias
+ );
+
+ return isset($row['id_alias']);
+ }
}
diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php
index 0bf22ae51..0c315bad0 100644
--- a/controllers/admin/AdminImportController.php
+++ b/controllers/admin/AdminImportController.php
@@ -88,6 +88,7 @@ class AdminImportControllerCore extends AdminController
$this->l('Addresses'),
$this->l('Manufacturers'),
$this->l('Suppliers'),
+ $this->l('Alias'),
);
// @since 1.5.0
@@ -360,7 +361,6 @@ class AdminImportControllerCore extends AdminController
'postcode' => 'X'
);
break;
-
case $this->entities[$this->l('Manufacturers')]:
case $this->entities[$this->l('Suppliers')]:
//Overwrite validators AS name is not MultiLangField
@@ -392,6 +392,23 @@ class AdminImportControllerCore extends AdminController
'shop' => Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT')),
);
break;
+ case $this->entities[$this->l('Alias')]:
+ //Overwrite required_fields
+ $this->required_fields = array(
+ 'alias',
+ 'search',
+ );
+ $this->available_fields = array(
+ 'no' => array('label' => $this->l('Ignore this column')),
+ 'id' => array('label' => $this->l('ID')),
+ 'alias' => array('label' => $this->l('Alias *')),
+ 'search' => array('label' => $this->l('Search *')),
+ 'active' => array('label' => $this->l('Active')),
+ );
+ self::$default_values = array(
+ 'active' => '1',
+ );
+ break;
}
// @since 1.5.0
@@ -2435,6 +2452,56 @@ class AdminImportControllerCore extends AdminController
$this->closeCsvFile($handle);
}
+ public function aliasImport()
+ {
+ $this->receiveTab();
+ $handle = $this->openCsvFile();
+ AdminImportController::setLocale();
+ for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++)
+ {
+ if (Tools::getValue('convert'))
+ $line = $this->utf8EncodeArray($line);
+ $info = AdminImportController::getMaskedRow($line);
+
+ AdminImportController::setDefaultValues($info);
+
+ if (Tools::getValue('forceIDs') && isset($info['id']) && (int)$info['id'])
+ $alias = new Alias((int)$info['id']);
+ else
+ {
+ if (array_key_exists('id', $info) && (int)$info['id'] && Alias::existsInDatabase((int)$info['id'], 'alias'))
+ $alias = new Alias((int)$info['id']);
+ else
+ $alias = new Alias();
+ }
+
+ AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $alias);
+
+ $res = false;
+ if (($field_error = $alias->validateFields(UNFRIENDLY_ERROR, true)) === true &&
+ ($lang_field_error = $alias->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
+ {
+ if ($alias->id && $alias->aliasExists($alias->id))
+ $res = $alias->update();
+ if (!$res)
+ $res = $alias->add();
+
+ if (!$res)
+ $this->errors[] = Db::getInstance()->getMsgError().' '.sprintf(
+ Tools::displayError('%1$s (ID: %2$s) cannot be saved'),
+ $info['name'],
+ (isset($info['id']) ? $info['id'] : 'null')
+ );
+ }
+ else
+ {
+ $this->errors[] = $this->l('Alias is invalid').' ('.$alias->name.')';
+ $this->errors[] = ($field_error !== true ? $field_error : '').(isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '');
+ }
+ }
+ $this->closeCsvFile($handle);
+ }
+
/**
* @since 1.5.0
*/
@@ -2782,6 +2849,9 @@ class AdminImportControllerCore extends AdminController
if (preg_match('/^[0-9]+(\-(.*))?\.jpg$/', $d))
unlink(_PS_SUPP_IMG_DIR_.$d);
break;
+ case $this->entities[$this->l('Alias')]:
+ Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'alias`');
+ break;
}
Image::clearTmpDir();
return true;
@@ -2880,6 +2950,9 @@ class AdminImportControllerCore extends AdminController
$this->supplierImport();
$this->clearSmartyCache();
break;
+ case $this->entities[$import_type = $this->l('Alias')]:
+ $this->aliasImport();
+ break;
}
// @since 1.5.0
diff --git a/docs/csv_import/alias_import.csv b/docs/csv_import/alias_import.csv
new file mode 100644
index 000000000..b64a435be
--- /dev/null
+++ b/docs/csv_import/alias_import.csv
@@ -0,0 +1,3 @@
+id;Alias *;Search *;Active (0/1)
+3;microsft,micro;microsoft;1
+4;adbe,adaub;adobe;1