[*] BO : #PSTEST-1141 : fix bugs in AdminImportController

This commit is contained in:
lLefevre
2012-04-11 11:58:27 +00:00
parent c2b5533d26
commit 5752456b17
3 changed files with 92 additions and 74 deletions
@@ -39,7 +39,7 @@
{/if}
{if $module_confirmation}
<div class="module_confirmation conf confirm"><img src="../img/admin/ok.gif" alt="" title="" style="margin-right:5px; float:left;" />
<div class="module_confirmation conf confirm">
{l s='Your .CSV file has been sucessfully imported into your shop.'}
</div>
{/if}
@@ -134,31 +134,30 @@
<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">{l s='What kind of Entity would you like to import ?'} </label>
<div class="margin-form">
<select name="entity" id="entity">
{foreach $entities AS $entity => $i}
<option value="{$i}"
{if $entity == $i}selected="selected"{/if}>
{$entity}
</option>
{/foreach}
</select>
</div>
<label class="clear">{l s='Your CSV file'} ({count($files_to_import)} {if count($files_to_import) > 1} {l s='files'}{else}{l s='file'}{/if}{l s='):'}</label>
<div class="margin-form">
{if count($files_to_import)}
<select name="csv">
{foreach $files_to_import AS $filename}
<option value="{$filename}">{$filename}</option>
{/foreach}
</select>
{/if}
&nbsp;&nbsp;
{if count($files_to_import)}
<select name="csv">
{foreach $files_to_import AS $filename}
<option value="{$filename}">{$filename}</option>
{/foreach}
</select>
{/if}
&nbsp;
<a href="#upload_file_import" id="upload_file_import_link" class="button"><img src="../img/admin/add.gif" alt="Uplaod" title="Upload" />{l s='Upload'}</a>
</div>
<br />
<label class="clear">{l s='What kind of Entity would you like to import ?'} </label>
<div class="margin-form">
<select name="entity" id="entity">
{foreach $entities AS $entity => $i}
<option value="{$i}" {if $entity == $i}selected="selected"{/if}>
{$entity}
</option>
{/foreach}
</select>
</div>
<label class="clear">{l s='Language of the file:'}</label>
<div class="margin-form">
@@ -192,7 +191,8 @@
<input name="match_ref" id="match_ref" type="checkbox" style="margin-top: 6px; display:none"/>
</div>
<div class="space margin-form">
<input type="submit" name="submitImportFile" value="{l s='Next step'}" class="button"/>
<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}
</div>
<div class="warn import_products_categories" style="margin-top: 20px;">
<p>{l s='Note that the category import does not support categories of the same name.'}</p>
@@ -205,9 +205,8 @@
<div class="warn" style="margin-top: 20px;">
<p>{l s='There is no CSV file available, please upload one using the \'Upload\' button above.'}</p>
<ul>
<li>{l s='You can read informations on CSV import at:'} <a href="http://www.prestashop.com/wiki/Troubleshooting_6/" target="_blank">http://www.prestashop.com/wiki/Troubleshooting_6/</a></li>
<li>
{l s='Read more about CSV format at:'} <a href="http://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">http://en.wikipedia.org/wiki/Comma-separated_values</a></li>
<li>{l s='You can read informations on CSV import at:'} <a href="http://www.prestashop.com/wiki/Troubleshooting_6/" target="_blank">http://www.prestashop.com/wiki/Troubleshooting_6/</a></li>
<li>{l s='Read more about CSV format at:'} <a href="http://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">http://en.wikipedia.org/wiki/Comma-separated_values</a></li>
</ul>
</div>
{/if}
+67 -49
View File
@@ -423,7 +423,6 @@ class AdminImportControllerCore extends AdminController
$warnings = array();
foreach ($this->warnings as $warning)
$warnings[] = $warning;
$this->displayWarning($warnings);
}
$files_to_import = scandir(_PS_ADMIN_DIR_.'/import/');
@@ -574,7 +573,13 @@ class AdminImportControllerCore extends AdminController
// toolbar (save, cancel, new, ..)
$this->initToolbar();
if ($this->display == 'import')
$this->content .= $this->renderView();
if (Tools::getValue('csv'))
$this->content .= $this->renderView();
else
{
$this->errors[] = $this->l('You must upload a file for go to the next step');
$this->content .= $this->renderForm();
}
else
$this->content .= $this->renderForm();
@@ -1240,28 +1245,36 @@ class AdminImportControllerCore extends AdminController
{
$product_has_images = (bool)Image::getImages($this->context->language->id, (int)$product->id);
foreach ($product->image as $key => $url)
{
$error = false;
if (!empty($url))
{
$image = new Image();
$image->id_product = (int)$product->id;
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = (!$key && !$product_has_images) ? true : false;
if (($field_error = $image->validateFields(UNFRIENDLY_ERROR, true)) === true &&
if (!file_exists($url))
$error = true;
else if (($field_error = $image->validateFields(UNFRIENDLY_ERROR, true)) === true &&
($lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $image->add())
{
// associate image to selected shops
$image->associateTo($shops);
if (!AdminImportController::copyImg($product->id, $image->id, $url))
$this->warnings[] = Tools::displayError('Error copying image:').$url;
$this->warnings[] = Tools::displayError('Error copying image:').' '.$url;
}
else
{
$this->warnings[] = (isset($image->id_product) ? ' ('.$image->id_product.')' : '').
' '.Tools::displayError('Cannot be saved');
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : '').
Db::getInstance()->getMsgError();
}
$error = true;
}
else
$error = true;
if ($error)
{
$this->warnings[] = sprintf(Tools::displayError('Product n°%1$d : the picture cannot be saved : %2$s'), $image->id_product, $url);
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : '').Db::getInstance()->getMsgError();
}
}
}
if (isset($product->id_category))
$product->updateCategories(array_map('intval', $product->id_category));
@@ -1347,8 +1360,7 @@ class AdminImportControllerCore extends AdminController
}
else
{
$this->warnings[] = (isset($image->id_product) ? ' ('.$image->id_product.')' : '').
' '.Tools::displayError('Cannot be saved');
$this->warnings[] = (isset($image->id_product) ? ' ('.$image->id_product.')' : '').' '.Tools::displayError('Cannot be saved');
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : '').mysql_error();
}
}
@@ -2240,45 +2252,51 @@ class AdminImportControllerCore extends AdminController
}
else if (Tools::getValue('import'))
{
if (Tools::getValue('truncate'))
$this->truncateTables((int)Tools::getValue('entity'));
switch ((int)Tools::getValue('entity'))
// Check if the CSV file exist
if (Tools::getValue('csv'))
{
case $this->entities[$this->l('Categories')]:
$this->categoryImport();
break;
case $this->entities[$this->l('Products')]:
$this->productImport();
break;
case $this->entities[$this->l('Customers')]:
$this->customerImport();
break;
case $this->entities[$this->l('Addresses')]:
$this->addressImport();
break;
case $this->entities[$this->l('Combinations')]:
$this->attributeImport();
break;
case $this->entities[$this->l('Manufacturers')]:
$this->manufacturerImport();
break;
case $this->entities[$this->l('Suppliers')]:
$this->supplierImport();
break;
// @since 1.5.0
case $this->entities[$this->l('SupplyOrders')]:
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$this->supplyOrdersImport();
break;
// @since 1.5.0
case $this->entities[$this->l('SupplyOrdersDetails')]:
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$this->supplyOrdersDetailsImport();
break;
default:
$this->errors[] = $this->l('Please select what you would like to import');
if (Tools::getValue('truncate'))
$this->truncateTables((int)Tools::getValue('entity'));
switch ((int)Tools::getValue('entity'))
{
case $this->entities[$this->l('Categories')]:
$this->categoryImport();
break;
case $this->entities[$this->l('Products')]:
$this->productImport();
break;
case $this->entities[$this->l('Customers')]:
$this->customerImport();
break;
case $this->entities[$this->l('Addresses')]:
$this->addressImport();
break;
case $this->entities[$this->l('Combinations')]:
$this->attributeImport();
break;
case $this->entities[$this->l('Manufacturers')]:
$this->manufacturerImport();
break;
case $this->entities[$this->l('Suppliers')]:
$this->supplierImport();
break;
// @since 1.5.0
case $this->entities[$this->l('SupplyOrders')]:
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$this->supplyOrdersImport();
break;
// @since 1.5.0
case $this->entities[$this->l('SupplyOrdersDetails')]:
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$this->supplyOrdersDetailsImport();
break;
default:
$this->errors[] = $this->l('Please select what you would like to import');
}
}
else
$this->errors[] = $this->l('You must upload a file for go to the next step');
}
parent::postProcess();
+1
View File
@@ -1540,6 +1540,7 @@ $_LANGADM['AdminImporte92cfa244b5eb9025d07522080468445'] = 'Écotaxe';
$_LANGADM['AdminImportea4788705e6873b424c65e91c2846b19'] = 'Annuler';
$_LANGADM['AdminImporteafce46b9013f4d12336785c388b664c'] = 'Exemple de fichier de adresses';
$_LANGADM['AdminImporteb931783a286222455893fb956d52cc9'] = 'Vous pouvez lire des informations sur l\'import CSV sur :';
$_LANGADM['AdminImportec135b63c4cd152420ce2c5c37666b88'] = 'Vous devez télécharger un fichier pour aller à la prochaine étape.';
$_LANGADM['AdminImportec136b444eede3bc85639fac0dd06229'] = 'Fournisseur';
$_LANGADM['AdminImportecc2c839377d44e39486e231322de623'] = 'ID règles de taxes';
$_LANGADM['AdminImportecde3e896afb64e9a48781b8363b9a03'] = 'Caractéristique(Nom:Valeur:Position)';