Merge remote-tracking branch 'origin/ticket/r16492-bulkupdate'

This commit is contained in:
Michael RICOIS 2018-03-12 09:48:05 +01:00
commit ffe8c187e8
2 changed files with 74 additions and 53 deletions

View File

@ -281,26 +281,26 @@ class TaxCore extends ObjectModel
*/ */
public static function getProductTaxRate($id_product, $id_address = NULL) public static function getProductTaxRate($id_product, $id_address = NULL)
{ {
$id_country = (int)Country::getDefaultCountryId(); $id_country = (int)Country::getDefaultCountryId();
$id_state = 0; $id_state = 0;
$id_county = 0; $id_county = 0;
$rate = 0; $rate = 0;
if (!empty($id_address)) if (!empty($id_address)) {
{ $address_infos = Address::getCountryAndState($id_address);
$address_infos = Address::getCountryAndState($id_address); if ($address_infos['id_country']) {
if ($address_infos['id_country']) $id_country = (int)($address_infos['id_country']);
{ $id_state = (int)$address_infos['id_state'];
$id_country = (int)($address_infos['id_country']); $id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
$id_state = (int)$address_infos['id_state'];
$id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
} }
if (!empty($address_infos['vat_number']) AND $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') AND Configuration::get('VATNUMBER_MANAGEMENT')) if (!empty($address_infos['vat_number']) AND $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') AND Configuration::get('VATNUMBER_MANAGEMENT')) {
return 0; return 0;
}
} }
if ($rate = Tax::getProductTaxRateViaRules((int)$id_product, (int)$id_country, (int)$id_state, (int)$id_county)) if ($rate = Tax::getProductTaxRateViaRules((int)$id_product, (int)$id_country, (int)$id_state, (int)$id_county)) {
return $rate; return $rate;
}
return $rate; return $rate;
} }

View File

@ -537,47 +537,53 @@ class AdminBulkUpdate extends AdminTab {
} }
$output .= '<p class="conf">'.$this->l('Products updated').'</p>'; $output .= '<p class="conf">'.$this->l('Products updated').'</p>';
} elseif(Tools::isSubmit('submitUploadPrices')) { }
// MAJ Rapide produits (Reduction, Prix d'achat HT, Prix d'achat TTC)
elseif(Tools::isSubmit('submitUploadPrices'))
{
$f = fopen($_FILES['csvfile']['tmp_name'], 'r'); $f = fopen($_FILES['csvfile']['tmp_name'], 'r');
fgetcsv($f, 0, ';'); fgetcsv($f, 0, ';');
$products = array(); $products = array();
$prices = array(); $prices = array();
if(Tools::getValue('price_process') == 2) { if (Tools::getValue('price_process') == 2) {
while($line = fgetcsv($f, 0, ';')) { while ($line = fgetcsv($f, 0, ';')) {
if(empty($line[0])) { if (empty($line[0])) {
continue; continue;
} }
$products[] = (int) $line[0]; $products[] = (int) $line[0];
} }
} elseif(Tools::getValue('price_process') == 3 }
|| Tools::getValue('price_process') == 4){ // Prix d'achat HT || Prix public TTC
while($line = fgetcsv($f, 0, ';')) { elseif (Tools::getValue('price_process') == 3 || Tools::getValue('price_process') == 4) {
if(empty($line[0])) { while ($line = fgetcsv($f, 0, ';')) {
if (empty($line[0])) {
continue; continue;
} }
$prices[] = array( $prices[] = array(
(int) $line[0], (int) $line[0],
$line[1] $line[1]
); );
} }
}else { }
while($line = fgetcsv($f, 0, ';')) { // Reduction
if(empty($line[0])) { else {
while ($line = fgetcsv($f, 0, ';')) {
if (empty($line[0])) {
continue; continue;
} }
if(!isset($line[1])) { if (!isset($line[1])) {
continue; continue;
} }
$products[] = (int) $line[0]; $products[] = (int) $line[0];
$prices[] = array( $prices[] = array(
(int) $line[0], (int) $line[0],
(float) $line[1] > 1? (float) $line[1] / 100: (float) $line[1] (float) $line[1] > 1 ? (float) $line[1] / 100: (float) $line[1]
); );
} }
@ -585,17 +591,18 @@ class AdminBulkUpdate extends AdminTab {
fclose($f); fclose($f);
if(Tools::getValue('price_process') == 1 // Reduction || ...
|| Tools::getValue('price_process') == 2) { if (Tools::getValue('price_process') == 1 || Tools::getValue('price_process') == 2) {
Db::getInstance()->ExecuteS(' Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'specific_price` DELETE FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_product` IN ('.implode(', ', $products).') WHERE `id_product` IN ('.implode(', ', $products).')
'); ');
} }
if(Tools::getValue('price_process') == 1) { // Reduction
foreach($prices as $price) { if (Tools::getValue('price_process') == 1) {
if((int) $price[0] != 0) { foreach ($prices as $price) {
if ((int) $price[0] != 0) {
Db::getInstance()->ExecuteS(' Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'specific_price` VALUES ( INSERT INTO `'._DB_PREFIX_.'specific_price` VALUES (
DEFAULT, DEFAULT,
@ -617,51 +624,64 @@ class AdminBulkUpdate extends AdminTab {
} }
} }
} }
if(Tools::getValue('price_process') == 3) {
foreach($prices as $price) { // Prix d'achat HT
if((int) $price[0] != 0){ if (Tools::getValue('price_process') == 3) {
foreach ($prices as $price) {
if ((int) $price[0] != 0){
$price[1] = str_replace(',', '.', $price[1]); $price[1] = str_replace(',', '.', $price[1]);
$price_ht = floatval($price[1]); $price_ht = floatval($price[1]);
Db::getInstance()->ExecuteS(' Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'product` UPDATE `'._DB_PREFIX_.'product`
SET wholesale_price = '. (float)$price_ht .' SET wholesale_price = '. (float)$price_ht .'
WHERE id_product ='. (int)$price[0]); WHERE id_product ='. (int)$price[0]);
}else{ } else {
$output .= '<p class="error">ID produit à 0, ligne non traitée : '.serialize($price).'</p>'; $output .= '<p class="error">ID produit à 0, ligne non traitée : '.serialize($price).'</p>';
} }
} }
} }
if(Tools::getValue('price_process') == 4) {
foreach($prices as $price) { // Prix public TTC
if((int) $price[0] != 0){ if (Tools::getValue('price_process') == 4) {
foreach ($prices as $price) {
if ((int) $price[0] != 0){
$price[1] = str_replace(',', '.', $price[1]); $price[1] = str_replace(',', '.', $price[1]);
$price_ht = floatval($price[1] / 1.20); // Find Tax for this id product
// product.id_tax_rules_group => tax_rules_group => tax_rule => tax.rate
$tax = new Tax();
$taxValue = $tax->getProductTaxRate((int)$price[0]);
if ($taxValue == 0) {
$taxValue = 20;
}
$price_ht = floatval($price[1] / (1 + $taxValue / 100) );
Db::getInstance()->ExecuteS(' Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'product` UPDATE `'._DB_PREFIX_.'product`
SET price = '. (float)$price_ht .' SET price = '. (float)$price_ht .'
WHERE id_product ='. (int)$price[0]); WHERE id_product ='. (int)$price[0]);
}else{ } else {
$output .= '<p class="error">ID produit à 0, ligne non traitée : '.serialize($price).'</p>'; $output .= '<p class="error">ID produit à 0, ligne non traitée : '.serialize($price).'</p>';
} }
} }
} }
$output .= '<p class="conf">'.$this->l('Products updated').'</p>'; $output .= '<p class="conf">'.$this->l('Products updated').'</p>';
} elseif(Tools::isSubmit('submitUploadProductDescriptions')) { }
elseif (Tools::isSubmit('submitUploadProductDescriptions')) {
$id_lang = Tools::getValue('description_process'); $id_lang = Tools::getValue('description_process');
$f = fopen($_FILES['csvfile']['tmp_name'], 'r'); $f = fopen($_FILES['csvfile']['tmp_name'], 'r');
fgetcsv($f, 0, ';'); fgetcsv($f, 0, ';');
$products = array(); $products = array();
while($line = fgetcsv($f, 0, ';')) { while ($line = fgetcsv($f, 0, ';')) {
if($line[0] == '' || $line[1] == '') { if ($line[0] == '' || $line[1] == '') {
continue; continue;
} }
$products[] = $line; $products[] = $line;
} }
foreach($products as $line) { foreach ($products as $line) {
$result = Db::getInstance()->ExecuteS(' $result = Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'product_lang` UPDATE `'._DB_PREFIX_.'product_lang`
SET `description` = "'. pSQL($line[1],true) .'" SET `description` = "'. pSQL($line[1],true) .'"
@ -675,14 +695,15 @@ class AdminBulkUpdate extends AdminTab {
fclose($f); fclose($f);
$output .= '<p class="conf">'.$this->l('Products updated').'</p>'; $output .= '<p class="conf">'.$this->l('Products updated').'</p>';
} elseif(Tools::isSubmit('submitUploadCombinations')) { }
elseif (Tools::isSubmit('submitUploadCombinations')) {
$f = fopen($_FILES['csvfile']['tmp_name'], 'r'); $f = fopen($_FILES['csvfile']['tmp_name'], 'r');
fgetcsv($f, 0, ';'); fgetcsv($f, 0, ';');
$products = array(); $products = array();
while($line = fgetcsv($f, 0, ';')) { while ($line = fgetcsv($f, 0, ';')) {
if(empty($line[0])) { if (empty($line[0])) {
continue; continue;
} }
@ -713,7 +734,7 @@ class AdminBulkUpdate extends AdminTab {
$output .= '<p class="conf">'.$this->l('Products updated').'</p>'; $output .= '<p class="conf">'.$this->l('Products updated').'</p>';
} elseif(Tools::isSubmit('submitExportDeb')){ } elseif (Tools::isSubmit('submitExportDeb')){
set_time_limit(300); set_time_limit(300);
$id_lang = Tools::getValue('id_lang', $cookie->id_lang); $id_lang = Tools::getValue('id_lang', $cookie->id_lang);
$deb = Tools::getValue('deb', 0); $deb = Tools::getValue('deb', 0);