[-] BO : fix #PSCFV-4596 : added an option for to force the id during CSV import

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17684 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
lLefevre
2012-10-02 12:08:41 +00:00
parent 00cb52c6f9
commit 976ffc3455
6 changed files with 35 additions and 9 deletions

View File

@@ -122,7 +122,7 @@
<fieldset style="float: left; margin: 0pt 20px 0pt 0pt; width: 70%;">
<legend><img src="../img/admin/import.gif" />{l s='Import'}</legend>
<label class="clear">{if count($files_to_import) > 1}{l s='Your CSV file (%d files):' sprintf=files_to_import}{else}{l s='Your CSV file (%d file):' sprintf=files_to_import}{/if}</label>
<label class="clear">{if count($files_to_import) > 1}{l s='Your CSV file (%d files):' sprintf=count($files_to_import)}{else}{l s='Your CSV file (%d file):' sprintf=count($files_to_import)}{/if}</label>
<div class="margin-form">
{if count($files_to_import)}
<select name="csv">
@@ -173,10 +173,14 @@
<div class="margin-form">
<input name="truncate" id="truncate" type="checkbox"/>
</div>
<label for="match_ref" class="clear" style="display: none">{l s='Use product reference as key?'}</label>
<label for="match_ref" class="clear" style="display: none">{l s='Use product reference as key?'}</label>
<div class="margin-form">
<input name="match_ref" id="match_ref" type="checkbox" style="margin-top: 6px; display:none"/>
</div>
<label for="forceIDs" class="clear">{l s='Force all ids during import?'} </label>
<div class="margin-form">
<input name="forceIDs" id="forceIDs" type="checkbox"/> {l s='If you don\'t use this option, all IDs will be auto-incremented.'}
</div>
<div class="space margin-form">
<input type="submit" name="submitImportFile" value="{l s='Next step'}" class="button" {if empty($files_to_import)}disabled{/if}/>
{if empty($files_to_import)}<span style="color:red;">{l s='You must upload a file for go to the next step.'}</span>{/if}
@@ -255,6 +259,11 @@
else
$(".import_products_categories").hide();
if ($("#entity > option:selected").val() == 0 || $("#entity > option:selected").val() == 1 || $("#entity > option:selected").val() == 3)
$("label[for=forceIDs],#forceIDs").show();
else
$("label[for=forceIDs],#forceIDs").hide();
$("#entitie").html($("#entity > option:selected").text().toLowerCase());
$.ajax({
url: 'ajax.php',

View File

@@ -67,6 +67,9 @@
{if $fields_value.truncate}
<input type="hidden" name="truncate" value="1" />
{/if}
{if $fields_value.forceIDs}
<input type="hidden" name="forceIDs" value="1" />
{/if}
{if $fields_value.match_ref}
<input type="hidden" name="match_ref" value="1" />
{/if}

View File

@@ -458,7 +458,7 @@ abstract class ObjectModelCore
}
// Database insertion
if (isset($this->id))
if (isset($this->id) && !Tools::getValue('forceIDs'))
unset($this->id);
if (Shop::checkIdShopDefault($this->def['table']))
$this->id_shop_default = min($id_shop_list);

View File

@@ -504,6 +504,7 @@ class AdminImportControllerCore extends AdminController
'entity' => (int)Tools::getValue('entity'),
'iso_lang' => Tools::getValue('iso_lang'),
'truncate' => Tools::getValue('truncate'),
'forceIDs' => Tools::getValue('forceIDs'),
'match_ref' => Tools::getValue('match_ref'),
'separator' => $this->separator,
'multiple_value_separator' => $this->multiple_value_separator
@@ -728,7 +729,7 @@ class AdminImportControllerCore extends AdminController
foreach (self::$column_mask as $type => $nb)
$res[$type] = isset($row[$nb]) ? $row[$nb] : null;
if (Tools::getValue('truncate')) //if you choose to truncate table before import the column id is remove from the CSV file.
if (Tools::getValue('forceIds')) // if you choose to force table before import the column id is remove from the CSV file.
unset($res['id']);
return $res;
@@ -850,7 +851,12 @@ class AdminImportControllerCore extends AdminController
continue;
}
AdminImportController::setDefaultValues($info);
$category = new Category();
if (Tools::getValue('forceIDs') && isset($info['id']) && (int)$info['id'])
$category = new Category((int)$info['id']);
else
$category = new Category();
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $category);
if (isset($category->parent) && is_numeric($category->parent))
@@ -863,7 +869,10 @@ class AdminImportControllerCore extends AdminController
{
$category_parent = Category::searchByName($default_language_id, $category->parent, true);
if ($category_parent['id_category'])
{
$category->id_parent = (int)$category_parent['id_category'];
$category->level_depth = (int)$category_parent['level_depth'] + 1;
}
else
{
$category_to_create = new Category();
@@ -1006,16 +1015,19 @@ class AdminImportControllerCore extends AdminController
if (Tools::getValue('convert'))
$line = $this->utf8EncodeArray($line);
$info = AdminImportController::getMaskedRow($line);
if (Tools::getValue('forceIDs') && isset($info['id']) && (int)$info['id'])
$product = new Product((int)$info['id']);
else
$product = new Product();
if (array_key_exists('id', $info) && (int)$info['id'] && Product::existsInDatabase((int)$info['id'], 'product'))
{
$product = new Product((int)$info['id']);
$product->loadStockData();
$category_data = Product::getProductCategories((int)$product->id);
foreach ($category_data as $tmp)
$product->category[] = $tmp;
}
else
$product = new Product();
AdminImportController::setEntityDefaultValues($product);
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);

View File

@@ -228,7 +228,7 @@ label {
font-weight:bold;
padding:0.2em 0 0;
text-align:left;
width:300px;
width:320px;
}
label.t {

View File

@@ -1321,6 +1321,7 @@ $_LANGADM['AdminImport2415390fb5052bb8221a93c9fc51b17f'] = 'Importer les donnée
$_LANGADM['AdminImport2688a544cd5ac33f27ab78c8d8c3acaa'] = 'Nom *';
$_LANGADM['AdminImport278c491bdd8a53618c149c4ac790da34'] = 'Modèle';
$_LANGADM['AdminImport284b47b0bb63ae2df3b29f0e691d6fcf'] = 'Adresses';
$_LANGADM['AdminImport28bc6f0862918aba3c4b3e80212a3fc5'] = 'Forcer tous les identifiants lors de l\'importation?';
$_LANGADM['AdminImport2a08996307b8694521492f3ca7b5df40'] = 'Exemple de fichier de déclinaisons';
$_LANGADM['AdminImport2a1a026f56b4c51cc839e513370379fd'] = 'Langue du fichier :';
$_LANGADM['AdminImport2a982c2c140ad66259355df1e2c5b69f'] = 'Méta description';
@@ -1363,6 +1364,7 @@ $_LANGADM['AdminImport6afcfa28445fa35c1f6618a471891ed8'] = 'La commande fourniss
$_LANGADM['AdminImport6c7c9fbb27699c4018dc15744547b4a4'] = 'Catégorie racine (0/1)';
$_LANGADM['AdminImport6d5030fd40c1e08767b4b70d3786b0fb'] = 'L\'ID du fournisseur (%d) n\'est pas valable(ligne %d).';
$_LANGADM['AdminImport70e7a6fcceb39a1e3ea3925182b85d18'] = 'AAAA-MM-JJ';
$_LANGADM['AdminImport72412dc8aa8825cd4f72b4fd1c0b05a2'] = 'Si vous n\'utilisez pas cette option, tous les identifiants seront générés via l\'auto-incrémentation.';
$_LANGADM['AdminImport72d6d7a1885885bb55a565fd1070581a'] = 'Import';
$_LANGADM['AdminImport72ef2b9b6965d078e3c7f95487a82d1c'] = 'Sauter';
$_LANGADM['AdminImport76aeea9f48196068e6b47d46d41e7618'] = 'Afficher le prix (0 = Non, 1 = Oui)';