Merge branch 'ticket-11279-CategoryTestImport' into develop
This commit is contained in:
commit
c9dd7475bc
@ -50,6 +50,7 @@ class AdminImport extends AdminTab
|
||||
public static $default_values = array();
|
||||
|
||||
public $_warnings = array();
|
||||
public $_categories = array();
|
||||
|
||||
public static $validators = array(
|
||||
'active' => array('AdminImport', 'getBoolean'),
|
||||
@ -86,7 +87,7 @@ class AdminImport extends AdminTab
|
||||
|
||||
self::$required_fields = array('id_product', 'options');
|
||||
$this->available_fields = array(
|
||||
'no' => array('label' => $this->l('Ignore this column')),
|
||||
'no' => array('label' => $this->l('Ignore this column')),
|
||||
'id_product' => array('label' => $this->l('Product ID').'*'),
|
||||
'options' => array('label' => $this->l('Options (Group:Value)').'*'),
|
||||
'reference' => array('label' => $this->l('Reference')),
|
||||
@ -99,7 +100,7 @@ class AdminImport extends AdminTab
|
||||
'quantity' => array('label' => $this->l('Quantity')),
|
||||
'weight' => array('label' => $this->l('Weight')),
|
||||
'default_on' => array('label' => $this->l('Default')),
|
||||
'image_position' => array('label' => $this->l('Image position'),
|
||||
'image_position' => array('label' => $this->l('Image position'),
|
||||
'help' => $this->l('Position of the product image to use for this combination. If you use this field, leave image URL empty.')),
|
||||
'image_url' => array('label' => $this->l('Image URL')),
|
||||
);
|
||||
@ -434,11 +435,11 @@ class AdminImport extends AdminTab
|
||||
|
||||
/**
|
||||
* copyImg copy an image located in $url and save it in a path
|
||||
* according to $entity->$id_entity .
|
||||
* according to $entity->$id_entity .
|
||||
* $id_image is used if we need to add a watermark
|
||||
*
|
||||
*
|
||||
* @param int $id_entity id of product or category (set in entity)
|
||||
* @param int $id_image (default null) id of the image if watermark enabled.
|
||||
* @param int $id_image (default null) id of the image if watermark enabled.
|
||||
* @param string $url path or url to use
|
||||
* @param string entity 'products' or 'categories'
|
||||
* @return void
|
||||
@ -605,11 +606,6 @@ class AdminImport extends AdminTab
|
||||
self::setEntityDefaultValues($product);
|
||||
self::array_walk($info, array('AdminImport', 'fillInfo'), $product);
|
||||
|
||||
// Override Antadis / Weight by default
|
||||
// if (empty($info['weight'])
|
||||
// && $info['weight'] != "0") {
|
||||
// $product->weight = 0.2;
|
||||
// }
|
||||
$iso_lang = trim(Tools::getValue('iso_lang'));
|
||||
if ($iso_lang == 'fr') {
|
||||
if (empty($info['weight']) && $info['weight'] != "0") {
|
||||
@ -684,17 +680,31 @@ class AdminImport extends AdminTab
|
||||
foreach ($product->category AS $value)
|
||||
{
|
||||
if (is_numeric($value))
|
||||
{
|
||||
{
|
||||
// @Override Antadis
|
||||
if(!isset($this->_categories[(int)$value])){
|
||||
$this->_categories[(int)$value] = 0;
|
||||
} elseif ($this->_categories[(int)$value] == 0) {
|
||||
continue 2;
|
||||
}
|
||||
|
||||
if($value > ($max_id_category + 1000)){
|
||||
echo "<div class='module_error error error'>";
|
||||
echo "Le numéro de catégorie ". $value." est supérieur de +1000 par rapport au dernier numéro connu " . $max_id_category;
|
||||
echo "</div>";
|
||||
die();
|
||||
}
|
||||
if (Category::categoryExists((int)($value)))
|
||||
if (Category::categoryExists((int)($value))) {
|
||||
// @Override Antadis
|
||||
$this->_categories[(int)$value] = 1;
|
||||
$product->id_category[] = (int)($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// @Override Antadis
|
||||
$this->_categories[(int)$value] = 0;
|
||||
continue 2;
|
||||
|
||||
$categoryToCreate= new Category();
|
||||
$categoryToCreate->id = (int)($value);
|
||||
$categoryToCreate->name = self::createMultiLangField($value);
|
||||
@ -758,7 +768,7 @@ class AdminImport extends AdminTab
|
||||
// check quantity
|
||||
if ($product->quantity == NULL)
|
||||
$product->quantity = 0;
|
||||
|
||||
|
||||
// If match ref is specified AND ref product AND ref product already in base, trying to update
|
||||
if (Tools::getValue('match_ref') == 1 AND $product->reference AND Product::existsRefInDatabase($product->reference))
|
||||
{
|
||||
@ -868,7 +878,7 @@ class AdminImport extends AdminTab
|
||||
$product->deleteImages();
|
||||
elseif (isset($product->image) AND is_array($product->image) AND sizeof($product->image))
|
||||
$product->deleteImages();
|
||||
|
||||
|
||||
if (isset($product->image) AND is_array($product->image) and sizeof($product->image))
|
||||
{
|
||||
$productHasImages = (bool)Image::getImages((int)($cookie->id_lang), (int)($product->id));
|
||||
@ -932,10 +942,10 @@ class AdminImport extends AdminTab
|
||||
$info = array_map('trim', $info);
|
||||
|
||||
self::setDefaultValues($info);
|
||||
|
||||
|
||||
$product = new Product((int)($info['id_product']), false, $defaultLanguage);
|
||||
$id_image = null;
|
||||
|
||||
|
||||
if (isset($info['image_url']) && $info['image_url'])
|
||||
{
|
||||
$productHasImages = (bool)Image::getImages((int)($cookie->id_lang), (int)($product->id));
|
||||
@ -1121,7 +1131,7 @@ class AdminImport extends AdminTab
|
||||
}
|
||||
|
||||
if (isset($address->customer_email) and !empty($address->customer_email))
|
||||
{
|
||||
{
|
||||
if ( Validate::isEmail($address->customer_email))
|
||||
{
|
||||
$customer = Customer::customerExists($address->customer_email, true);
|
||||
@ -1425,7 +1435,7 @@ class AdminImport extends AdminTab
|
||||
$("label[for=match_ref],#match_ref").show();
|
||||
}
|
||||
$("#entitie").html($("#entity > option:selected").text().toLowerCase());
|
||||
$.getJSON("'.dirname($currentIndex).'/ajax.php",
|
||||
$.getJSON("'.dirname($currentIndex).'/ajax.php",
|
||||
{
|
||||
getAvailableFields:1,
|
||||
entity: $("#entity").val()},
|
||||
@ -1461,7 +1471,7 @@ class AdminImport extends AdminTab
|
||||
$value = str_replace("\x9C", "oe", $value);
|
||||
$array = utf8_encode($array);
|
||||
}
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@ -1490,7 +1500,7 @@ class AdminImport extends AdminTab
|
||||
|
||||
if (!$handle)
|
||||
die(Tools::displayError('Cannot read the CSV file'));
|
||||
|
||||
|
||||
self::rewindBomAware($handle);
|
||||
|
||||
for ($i = 0; $i < (int)(Tools::getValue('skip')); ++$i)
|
||||
@ -1551,7 +1561,7 @@ class AdminImport extends AdminTab
|
||||
{
|
||||
global $currentIndex;
|
||||
$importMatchs = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'import_match');
|
||||
|
||||
|
||||
echo '
|
||||
<script src="'._PS_JS_DIR_.'adminImport.js"></script>
|
||||
<script type="text/javascript">
|
||||
@ -1569,7 +1579,7 @@ class AdminImport extends AdminTab
|
||||
</select>
|
||||
<a class="button" id="loadImportMatchs" href="#">'.$this->l('Load').'</a>
|
||||
<a class="button" id="deleteImportMatchs" href="#">'.$this->l('Delete').'</a>';
|
||||
|
||||
|
||||
echo '</div></div><h3>'.$this->l('Please set the value type of each column').'</h3>
|
||||
<div id="error_duplicate_type" class="warning warn" style="display:none;">
|
||||
<h3>'.$this->l('Columns cannot have the same value type').'</h3>
|
||||
@ -1743,7 +1753,7 @@ class AdminImport extends AdminTab
|
||||
$this->_errors[] = Tools::displayError('No file was uploaded');
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (!file_exists($_FILES['file']['tmp_name']) OR !@move_uploaded_file($_FILES['file']['tmp_name'], dirname(__FILE__).'/../import/'.$_FILES['file']['name'].'.'.date('Ymdhis')))
|
||||
$this->_errors[] = $this->l('an error occurred while uploading and copying file');
|
||||
@ -1783,6 +1793,13 @@ class AdminImport extends AdminTab
|
||||
default:
|
||||
$this->_errors[] = $this->l('no entity selected');
|
||||
}
|
||||
if(!empty($this->_categories)){
|
||||
foreach ($this->_categories as $key => $value) {
|
||||
if ($value == 0) {
|
||||
$this->_warnings[] = Tools::displayError('Products associated to this category have not been added because the category does not exist: ').$key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user