[*] BO #PSFV-94 : Added AdminImportController

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9974 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
lLefevre
2011-11-08 17:54:08 +00:00
parent c8556afc76
commit fc8b5cda7c
10 changed files with 2210 additions and 1872 deletions
+1 -3
View File
@@ -193,10 +193,8 @@ if ($step = (int)(Tools::getValue('ajaxProductTab')))
if (Tools::isSubmit('getAvailableFields') AND Tools::isSubmit('entity'))
{
AdminTab::$currentIndex = 'index.php?tab=AdminImport';
$jsonArray = array();
require_once(dirname(__FILE__).'/tabs/AdminImport.php');
$import = new AdminImport();
$import = new AdminImportController();
$languages = Language::getLanguages(false);
$defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
File diff suppressed because it is too large Load Diff
+234
View File
@@ -0,0 +1,234 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 8971 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{if $show_toolbar}
<div class="toolbar-placeholder">
<div class="toolbarBox{if $toolbar_fix} toolbarHead{/if}">
{include file="toolbar.tpl" toolbar_btn=$toolbar_btn}
<div class="pageTitle">
<h3>
<span id="current_obj" style="font-weight: normal;">{$title|default:'&nbsp;'}</span>
</h3>
</div>
<div class="leadin">{block name="leadin"}{/block}</div>
</div>
</div>
{/if}
{if $module_confirmation}
<div class="module_confirmation conf confirm"><img src="../img/admin/ok.gif" alt="" title="" style="margin-right:5px; float:left;" />
{l s='The .CSV file has been imported into your shop.'}
</div>
{/if}
<script type="text/javascript">
$(document).ready(function(){
activeClueTip();
});
function activeClueTip()
{
$('.info').cluetip({
splitTitle: '|',
showTitle: false
});
$('#preview_import').submit(function() {
if ($('#truncate').get(0).checked)
{
if (confirm('{l s="Are you sure you want to delete"}' + ' ' + $('#entity > option:selected').text().toLowerCase() + '{l s="?"}'))
{
this.submit();
}
else
{
return false;
}
}
});
};
</script>
<fieldset style="float: left; margin: 0pt 20px 0pt 0pt; height: 160px;width: 666px;">
<legend><img src="../img/admin/import.gif" />{l s='Upload'}</legend>
<form action="{$current}&token={$token}" method="POST" enctype="multipart/form-data">
<label class="clear">{l s='Select a file:'} </label>
<div class="margin-form">
<input name="file" type="file" /><br />{l s='You can also upload your file by FTP and put it in'} {$path_import}.
</div>
<div class="margin-form">
<input type="submit" name="submitFileUpload" value="{l s='Upload'}" class="button" />
</div>
<div class="margin-form">
{l s='Allowed files are only UTF-8 and iso-8859-1 encoded ones'}
</div>
</form>
</fieldset>
<fieldset>
<legend><img src="../img/admin/excel_file.png">{l s='Sample files'}</legend>
<ul style="">
<li style="text-decoration: underline"><a href="../docs/csv_import/categories_import.csv">{l s='Categories sample file'}</a></li>
<li style="text-decoration: underline"><a href="../docs/csv_import/products_import.csv">{l s='Products sample file'}</a></li>
<li style="text-decoration: underline"><a href="../docs/csv_import/combinations_import.csv">{l s='Combinations sample file'}</a></li>
<li style="text-decoration: underline"><a href="../docs/csv_import/customers_import.csv">{l s='Customers sample file'}</a></li>
<li style="text-decoration: underline"><a href="../docs/csv_import/addresses_import.csv">{l s='Addresses sample file'}</a></li>
<li style="text-decoration: underline"><a href="../docs/csv_import/manufacturers_import.csv">{l s='Manufacturers sample file'}</a></li>
<li style="text-decoration: underline"><a href="../docs/csv_import/suppliers_import.csv">{l s='Suppliers sample file'}</a></li>
</ul>
</fieldset>
<div class="clear">&nbsp;</div>
<form id="preview_import"
action="{$current}&token={$token}"
method="post"
style="display:inline"
enctype="multipart/form-data"
class="clear">
<fieldset style="float: left; margin: 0pt 20px 0pt 0pt; width: 666px;">
<legend><img src="../img/admin/import.gif" />{l s='Import'}</legend>
<label class="clear">{l s='Select which entity 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>
{if count($files_to_import)}
<label class="clear">{l s='Select your .CSV file:'} </label>
<div class="margin-form">
<select name="csv">
{foreach $files_to_import AS $filename}
<option value="{$filename}">{$filename}</option>
{/foreach}
</select>
({count($files_to_import)} {if count($files_to_import) > 1} {l s='files available'}{else}{l s='file available'}{/if})
</div>
<label class="clear">{l s='Select language of the file (the locale must be installed):'} </label>
<div class="margin-form">
<select name="iso_lang">';
{foreach $languages AS $lang}
<option value="{$lang.iso_code}" {if $lang.id_lang == $id_language} selected="selected"{/if}>{$lang.name}</option>
{/foreach}
</select>
</div>
<label for="convert" class="clear">{l s='iso-8859-1 encoded file:'} </label>
<div class="margin-form">
<input name="convert" id="convert" type="checkbox" style="margin-top: 6px;"/>
</div>
<label class="clear">{l s='Field separator:'} </label>
<div class="margin-form">
<input type="text" size="2" value=";" name="separator"/>
{l s='e.g. '}"1<span class="bold" style="color: red">;</span>Ipod<span class="bold" style="color: red">;</span>129.90<span class="bold" style="color: red">;</span>5"
</div>
<label class="clear">{l s='Multiple value separator:'} </label>
<div class="margin-form">
<input type="text" size="2" value="," name="multiple_value_separator"/>
{l s='e.g. '}"Ipod;red.jpg<span class="bold" style="color: red">,</span>blue.jpg<span class="bold" style="color: red">,</span>green.jpg;129.90"
</div>
<label for="truncate" class="clear">{l s='Delete all'} <span id="entitie">{l s='categories'}</span> {l s='before import ?'} </label>
<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>
<div class="margin-form">
<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"/>
</div>
<div class="warn">
<p>{l s='Note that the category import does not support categories of the same name'}.</p>
<p>{l s='Note that references are not specified as UNIQUE in the database'}.</p>
</div>
{else}
<div class="warn">
{l s='No CSV file is available, please upload one file above.'}<br /><br />
{l s='You can get many informations about CSV import at:'} <a href="http://www.prestashop.com/wiki/Troubleshooting_6/" target="_blank">http://www.prestashop.com/wiki/Troubleshooting_6/</a><br /><br />
{l s='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>
</div>
{/if}
</fieldset>
</form>
<fieldset>
<legend>
<img src="../img/admin/import.gif" />{l s='Fields available'}
</legend>
<div id="availableFields" style="min-height: 218px; width: 300px;">
{$available_fields}
</div>
<div class="clear">
<br /><br />{l s='* Required Fields'}
</div>
</fieldset>
<div class="clear">&nbsp;</div>
<script type="text/javascript">
$("select#entity").change( function() {
if ($("#entity > option:selected").val() != 1)
{
$("label[for=match_ref],#match_ref").hide();
}
if ($("#entity > option:selected").val() == 1)
{
$("label[for=match_ref],#match_ref").show();
}
$("#entitie").html($("#entity > option:selected").text().toLowerCase());
$.getJSON("ajax.php",
{
getAvailableFields:1,
entity: $("#entity").val()
},
function(j)
{
var fields = "";
$("#availableFields").empty();
for (var i = 0; i < j.length; i++)
fields += j[i].field;
$("#availableFields").html(fields);
activeClueTip();
});
});
</script>
+125
View File
@@ -0,0 +1,125 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 8971 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{extends file="helper/view/view.tpl"}
{block name="override_tpl"}
<script src="../js/adminImport.js"></script>
<script type="text/javascript">
var errorEmpty = "{l s='Please enter a name to save.'}"
</script>
<h2>{l s='Your data'}</h2>
<div style="float:right">
<b>{l s='Save and load your matching configuration'} : </b><br><br>
<input type="text" name="newImportMatchs" id="newImportMatchs">
<a id="saveImportMatchs" class="button" href="#">{l s='Save'}</a><br><br>
<div id="selectDivImportMatchs" {if !$import_matchs}style="display:none"{/if}>
<select id="valueImportMatchs">
{foreach $import_matchs as $match}
<option id="{$match.id_import_match}" value="{$match.match}">{$match.name}</option>
{/foreach}
</select>
<a class="button" id="loadImportMatchs" href="#">{l s='Load'}</a>
<a class="button" id="deleteImportMatchs" href="#">{l s='Delete'}</a>
</div>
</div>
<h3>{l s='Please set the value type of each column'}</h3>
<div id="error_duplicate_type" class="warning warn" style="display:none;">
<h3>{l s='Columns cannot have the same value type'}</h3>
</div>
<div id="required_column" class="warning warn" style="display:none;">
<h3>'.Tools::displayError('Column').' <span id="missing_column">&nbsp;</span> '.Tools::displayError('must be set').'</h3>
</div>
<form action="{$current}&token={$token}" method="post" id="import_form" name="import_form">
{l s='Skip'} <input type="text" size="2" name="skip" value="0" /> {l s='lines'}
<input type="hidden" name="csv" value="{$fields_value.csv}" />
<input type="hidden" name="convert" value="{$fields_value.convert}" />
<input type="hidden" name="entity" value="{$fields_value.entity}" />
<input type="hidden" name="iso_lang" value="{$fields_value.iso_lang}" />
{if $fields_value.truncate}
<input type="hidden" name="truncate" value="1" />
{/if}
{if $fields_value.match_ref}
<input type="hidden" name="match_ref" value="1" />
{/if}
<input type="hidden" name="separator" value="{$fields_value.separator}">
<input type="hidden" name="multiple_value_separator" value="{$fields_value.multiple_value_separator}">
<script type="text/javascript">
var current = 0;
function showTable(nb)
{
getE('btn_left').disabled = null;
getE('btn_right').disabled = null;
if (nb <= 0)
{
nb = 0;
getE('btn_left').disabled = 'true';
}
if (nb >= {$nb_table} - 1)
{
nb = {$nb_table} - 1;
getE('btn_right').disabled = 'true';
}
toggle(getE('table'+current), false);
current = nb;
toggle(getE('table'+current), true);
}
</script>
<table>
<tr>
<td colspan="3" align="center">
<input name="import" type="submit" onclick="return (validateImportation(new Array({$res})));" id="import" value="{l s='Import CSV data'}" class="button" />
</td>
</tr>
<tr>
<td valign="top" align="center">
<input id="btn_left" value="{l s='<<'}" type="button" class="button" onclick="showTable(current - 1)" />
</td>
<td align="left">
{section name=nb_i start=0 loop=$nb_table step=1}
{assign var=i value=$smarty.section.nb_i.index}
{$data.$i}
{/section}
</td>
<td valign="top" align="center">
<input id="btn_right" value="{l s='>>'}" type="button" class="button" onclick="showTable(current + 1)" />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input name="import" type="submit" onclick="return (validateImportation(new Array({$res})));" id="import" value="{l s='Import CSV data'}" class="button" />
</td>
</tr>
</table>
<script type="text/javascript">showTable(current);</script>
</form>
{/block}
+1 -1
View File
@@ -333,7 +333,7 @@ class AddressCore extends ObjectModel
$address = new Address((int)$id_address);
if (!Validate::isLoadedObject($address))
throw new Exception('Invalid address');
throw new PrestashopException('Invalid address');
}
return $address;
-1
View File
@@ -86,7 +86,6 @@ class HelperFormCore extends Helper
'title' => $this->title,
'firstCall' => $this->first_call,
'current' => $this->currentIndex,
'title' => $this->title,
'token' => $this->token,
'table' => $this->table,
'languages' => $this->languages,
+22
View File
@@ -259,6 +259,28 @@ class ShopCore extends ObjectModel
return $shop;
}
/**
* @return Address the current shop address
*/
public function getAddress()
{
if (!isset($this->address))
{
$address = new Address();
$address->company = Configuration::get('PS_SHOP_NAME');
$address->id_country = Configuration::get('PS_SHOP_COUNTRY_ID');
$address->id_state = Configuration::get('PS_SHOP_STATE_ID');
$address->address1 = Configuration::get('PS_SHOP_ADDR1');
$address->address2 = Configuration::get('PS_SHOP_ADDR2');
$address->postcode = Configuration::get('PS_SHOP_CODE');
$address->city = Configuration::get('PS_SHOP_CITY');
$this->address = $address;
}
return $this->address;
}
/**
* Get shop theme name
*
File diff suppressed because it is too large Load Diff