Merge branch 'ticket-12204-ImportEan'

This commit is contained in:
Marion Muszynski 2017-01-18 12:31:24 +01:00
commit 08443a1b69

View File

@ -48,7 +48,67 @@ class AdminBulkUpdate extends AdminTab {
fclose($f);
$output .= '<p class="conf">'.$this->l('Product customs updated').'</p>';
}
}elseif (Tools::isSubmit('submitUploadQuantities')) {
}elseif (Tools::isSubmit('submitUploadEans')) {
if(isset($_FILES['csvfile']) && $_FILES['csvfile']['name'] != '') {
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
fgetcsv($f, 0, ';');
$i = 1;
while($line = fgetcsv($f, 0, ';')) {
$i++;
$product = new Product((int) $line[0]);
if(Validate::isLoadedObject($product)) {
if(isset($line[2]) && $line[2] != '' && !Validate::isEan13($line[2])) {
$output .= '<p class="error">'.$this->l('Invalid ean for this product ID on line').' '.$i.'</p>';
continue;
}
if((int) $line[1] != 0) {
if(!Db::getInstance()->getRow('
SELECT `id_product_attribute`
FROM `'._DB_PREFIX_.'product_attribute`
WHERE `id_product` = '.(int) $line[0].'
AND `id_product_attribute` = '.(int) $line[1].'
')) {
$output .= '<p class="error">'.$this->l('Invalid attribute ID for this product ID on line').' '.$i.'</p>';
continue;
}
}
if((int) $line[1] != 0) {
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'product_attribute`
SET `ean13` = "'.pSQL($line[2]).'"
WHERE `id_product` = '.(int) $line[0].'
AND `id_product_attribute` = '.(int) $line[1].'
LIMIT 1
');
} else {
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'product`
SET `ean13` = "'.pSQL($line[2]).'"
WHERE `id_product` = '.(int) $line[0].'
LIMIT 1
');
}
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'order_detail`
SET `product_ean13` = "'.pSQL($line[2]).'"
WHERE `product_id` = '.(int) $line[0].'
AND `product_attribute_id` = '.(int) $line[1].'
');
} else {
$output .= '<p class="warn">'.$this->l('Product #').(int) $line[0].' '.$this->l('not found').'</p>';
}
}
fclose($f);
$output .= '<p class="conf">'.$this->l('Products updated').'</p>';
} else {
$output .= '<p class="conf">'.$this->l('Pas de fichier csv !').'</p>';
}
} elseif (Tools::isSubmit('submitUploadQuantities')) {
$process = (int) Tools::getValue('qty_process');
if(isset($_FILES['csvfile']) && $_FILES['csvfile']['name'] != '') {
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
@ -2103,6 +2163,20 @@ class AdminBulkUpdate extends AdminTab {
</fieldset>
</form>';
$output .= '
<p><br /></p>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
<fieldset><legend><img src="/modules/bulkupdate/logo.gif" alt="" title="" />'.$this->l('Update EAN').'</legend>
<label>'.$this->l('File:').'</label>
<div class="margin-form">
<input type="file" name="csvfile" />
<p>'.$this->l('Format: id_product;id_product_attribute;ean -- the subsequent columns and the first line are ignored').'</p>
</div>
<p> </p>
<center><input type="submit" name="submitUploadEans" value="'.$this->l('Upload').'" class="button" /></center>
</fieldset>
</form>';
$output .= '
<p><br /></p>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">