Merge pull request #841 from indesign47/patch-10
[+] BO : AdminImport add entity Alias
This commit is contained in:
@@ -77,6 +77,7 @@
|
||||
<li><a class="_blank" href="../docs/csv_import/addresses_import.csv">{l s='Sample Addresses file'}</a></li>
|
||||
<li><a class="_blank" href="../docs/csv_import/manufacturers_import.csv">{l s='Sample Manufacturers file'}</a></li>
|
||||
<li><a class="_blank" href="../docs/csv_import/suppliers_import.csv">{l s='Sample Suppliers file'}</a></li>
|
||||
<li><a class="_blank" href="../docs/csv_import/alias_import.csv">{l s='Sample Alias file'}</a></li>
|
||||
{if $PS_ADVANCED_STOCK_MANAGEMENT}
|
||||
<li><a class="_blank" href="../docs/csv_import/supply_orders_import.csv">{l s='Supply Orders sample file'}</a></li>
|
||||
<li><a class="_blank" href="../docs/csv_import/supply_orders_details_import.csv">{l s='Supply Orders Details sample file'}</a></li>
|
||||
@@ -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 @@
|
||||
});
|
||||
};
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
id;Alias *;Search *;Active (0/1)
|
||||
3;microsft,micro;microsoft;1
|
||||
4;adbe,adaub;adobe;1
|
||||
|
Reference in New Issue
Block a user